2 # ======================================================================
3 # ======================================================================
9 # ======================================================================
11 # ======================================================================
13 use constant START_BOOTLEG_TEST
=> "A";
14 use constant END_COMMUNICATION
=> "B";
15 use constant SUCCESSFUL_TEST
=> "C";
16 use constant UNSUCCESSFUL_TEST
=> "D";
17 use constant SERVER_READY
=> "E";
18 use constant BOOTLEG_MISMATCH
=> "F";
19 use constant CLIENT_KILL
=> "G";
20 use constant CLIENT_OK
=> "H";
22 # ======================================================================
24 # ======================================================================
27 $scriptName =~ s/^(.*)\\//;
34 # ======================================================================
36 # ======================================================================
40 die "\n\t$scriptName\n\n";
47 # find out where a perforce file resides on the local machine
50 open(P4
, "p4 where $_[0] |");
63 print STDERR
"Error with: $_[0]\n" if(defined $_[0]);
64 print STDERR
"Exiting this connection\n";
70 print "Installing bootleg...\n";
72 open(INSTALL
, "perl " . perforceWhere
("//depot/swg/current/tools/InstallBootleg.pl") . " --list --force_newest --client_only $branch |") or reloop
"Error running InstallBootleg.pl\n";
79 $bootlegnum = $1 if(/^Updating to build: (\d+)/);
80 $complete = 1 if(/^Update complete/);
85 print "Bootleg installation incomplete\n" if(!$complete);
86 print "Completed installing bootleg.\n" if($complete);
93 my $message = shift @_;
94 print SOCKET UNSUCCESSFUL_TEST
;
95 print STDERR
"$message\n";
101 my $message = shift @_;
102 print SOCKET UNSUCCESSFUL_TEST
;
110 @tok = split(/\\|\//, $_[0]);
112 $check = shift(@tok);
127 print STDERR
"Initializing communication...\n";
129 error
("problem reading from socket") if (read(SOCKET
, $buffer, 4) != 4);
130 my $length = unpack("N", $buffer);
131 error
("problem reading from socket") if(read(SOCKET
, $branch, $length) != $length);
133 print STDERR
"Testing bootleg for branch: $branch\n";
135 my $bootlegdir = perforceWhere
("//depot/swg/$branch/bootleg/win32/...");
136 $bootlegdir =~ s/\.{3}//;
138 chdir($bootlegdir) or reloop
"Cannot change to bootleg directory\n";
140 installBootleg
() || fatal
"Error installing bootleg";
142 print SOCKET
pack("N", $bootlegnum);
144 error
("problem reading from socket") if (read(SOCKET
, $buffer, 1) != 1);
145 error
("mismatch in client / server bootlegs")if($buffer eq BOOTLEG_MISMATCH
);
146 error
("server not ready") if ($buffer ne SERVER_READY
);
147 print STDERR
"Bootleg $bootlegnum verified with server - running client...\n";
149 # Get the ip of the server machine
150 my $other_socket = getpeername(SOCKET
) || reloop
"Couldn't identify other end: $!\n";
151 my ($other_port, $other_ip) = unpack_sockaddr_in
($other_socket);
152 my $server_ip = inet_ntoa
($other_ip);
155 my $swgpid = open(SWGCLIENT
, "SwgClient_o.exe -- -s ClientGame loginServerAddress=$server_ip skipIntro=true skipSplash=true autoConnectToLoginServer=true loginClientID=bootleg loginClientPassword=bootleg avatarName=\"bootleg bootleg\" autoConnectToGameServer=true autoQuitAfterLoadScreen=true -s SharedFoundation demoMode=true |");
156 error
("problem reading from socket") if (read(SOCKET
, $buffer, 1) != 1);
157 if($buffer eq CLIENT_KILL
)
160 error
("Test unsuccessful - forced to kill client");
162 elsif($buffer eq CLIENT_OK
)
164 # make sure we give the client a chance to exit on its own, then attempt to kill
165 print "Waiting for $waittime seconds for the client to end on its own...\n";
167 $killresult = kill 1, $swgpid;
171 # clientResult = 1 if return value of SwgClient == 0 and we did not have to kill it ($killresult = 0)
172 my $clientResult = (!($?
>> 8) && !$killresult);
173 print "clientresult=$clientResult killresult=$killresult exitresult=$?\n";
175 print SOCKET
($clientResult == 1) ? SUCCESSFUL_TEST
: UNSUCCESSFUL_TEST
;
177 print STDERR
"Test was " . (($clientResult == 1) ?
"successful\n" : "unsuccessful\n") . "\n";
180 # ======================================================================
182 # ======================================================================
184 # open the daemon socket
185 print STDERR
"Opening socket\n";
186 socket(LISTEN
, PF_INET
, SOCK_STREAM
, getprotobyname('tcp')) || die "socket failed\n";
187 setsockopt(LISTEN
, SOL_SOCKET
, SO_REUSEADDR
, 1) || die "setsockopt failed\n";
188 my $addr = sockaddr_in
($port, INADDR_ANY
);
189 bind(LISTEN
, $addr) || die "bind failed\n";
190 listen(LISTEN
, 1) || die "listen failed\n";
195 print STDERR
"Waiting on a connection...\n";
197 accept(SOCKET
, LISTEN
) || reloop
"accept failed\n";
199 # make binary and unbuffer the socket
201 my $oldSelect = select(SOCKET
);
206 error
("problem reading from socket") if (read(SOCKET
, $buffer, 1) != 1);
208 if($buffer eq START_BOOTLEG_TEST
)
210 print "Got message to initiate bootleg test.\n";