--- a/hedgewars/uFLGameConfig.pas Sat Dec 05 16:14:59 2015 +0300
+++ b/hedgewars/uFLGameConfig.pas Sun Dec 06 19:56:33 2015 +0300
@@ -29,6 +29,7 @@
procedure netSetAmmo(name: shortstring; definition: ansistring);
procedure netSetScheme(scheme: TScheme);
procedure netAddTeam(team: TTeam);
+procedure netAcceptedTeam(teamName: shortstring);
procedure netSetTeamColor(team: shortstring; color: Longword);
procedure netSetHedgehogsNumber(team: shortstring; hogsNumber: Longword);
procedure netRemoveTeam(teamName: shortstring);
@@ -38,7 +39,7 @@
procedure sendConfig(config: PGameConfig);
implementation
-uses uFLIPC, uFLUtils, uFLTeams, uFLThemes, uFLSChemes, uFLAmmo, uFLUICallback, uFLRunQueue;
+uses uFLIPC, uFLUtils, uFLTeams, uFLThemes, uFLSChemes, uFLAmmo, uFLUICallback, uFLRunQueue, uFLNet;
var
currentConfig: TGameConfig;
@@ -192,6 +193,12 @@
team: PTeam;
c: Longword;
begin
+ team:= teamByName(teamName);
+ if team = nil then exit;
+
+ if isConnected then
+ sendTeam(team^)
+ else
with currentConfig do
begin
hedgehogsNumber:= 0;
@@ -206,9 +213,6 @@
// no free space for a team or reached hogs number maximum
if (i > 7) or (hedgehogsNumber >= 48) then exit;
- team:= teamByName(teamName);
- if team = nil then exit;
-
c:= getUnusedColor;
teams[i]:= team^;
@@ -447,6 +451,7 @@
c:= getUnusedColor;
teams[i]:= team;
+ teams[i].extDriven:= true;
if i = 0 then hn:= 4 else hn:= teams[i - 1].hogsNumber;
if hn > 48 - hedgehogsNumber then hn:= 48 - hedgehogsNumber;
@@ -462,6 +467,52 @@
end
end;
+procedure netAcceptedTeam(teamName: shortstring);
+var msg: ansistring;
+ i, hn, hedgehogsNumber: Longword;
+ c: Longword;
+ team: PTeam;
+begin
+ with currentConfig do
+ begin
+ team:= teamByName(teamName);
+ // no such team???
+ if team = nil then exit;
+
+ hedgehogsNumber:= 0;
+ i:= 0;
+
+ while (i < 8) and (teams[i].hogsNumber > 0) do
+ begin
+ inc(i);
+ inc(hedgehogsNumber, teams[i].hogsNumber)
+ end;
+
+ // no free space for a team - server bug???
+ if (i > 7) or (hedgehogsNumber >= 48) then exit;
+
+ c:= getUnusedColor;
+
+ teams[i]:= team^;
+ teams[i].extDriven:= false;
+
+ if i = 0 then hn:= 4 else hn:= teams[i - 1].hogsNumber;
+ if hn > 48 - hedgehogsNumber then hn:= 48 - hedgehogsNumber;
+ teams[i].hogsNumber:= hn;
+
+ teams[i].color:= c;
+
+ msg:= '0' + #10 + teamName;
+ sendUI(mtAddPlayingTeam, @msg[1], length(msg));
+
+ msg:= teamName + #10 + colorsSet[teams[i].color];
+ sendUI(mtTeamColor, @msg[1], length(msg));
+
+ msg:= teamName;
+ sendUI(mtRemoveTeam, @msg[1], length(msg))
+ end
+end;
+
procedure netRemoveTeam(teamName: shortstring);
var msg: shortstring;
i: Longword;
--- a/hedgewars/uFLNet.pas Sat Dec 05 16:14:59 2015 +0300
+++ b/hedgewars/uFLNet.pas Sun Dec 06 19:56:33 2015 +0300
@@ -8,6 +8,8 @@
procedure sendNet(s: shortstring);
procedure sendNetLn(s: shortstring);
+var isConnected: boolean = false;
+
implementation
uses SDLh, uFLIPC, uFLTypes, uFLUICallback, uFLNetTypes, uFLUtils;
@@ -17,11 +19,9 @@
function getCurrChar: char; forward;
type
- TNetState = (netDisconnected, netConnecting);
TParserState = record
cmd: TCmdType;
l: LongInt;
- netState: TNetState;
buf: shortstring;
bufpos: byte;
end;
@@ -284,7 +284,7 @@
c:= getNextChar;
//writeln('>>>>> ', c, ' [', letters[state.l], '] ', commands[state.l], ' ', state.l);
if c = #0 then
- state.netState:= netDisconnected
+ isConnected:= false
else
begin
while (letters[state.l] <> c) and (commands[state.l] > 0) do
@@ -305,7 +305,7 @@
handler__UNKNOWN_()
end
end
- until state.netState = netDisconnected;
+ until not isConnected;
SDLNet_TCP_Close(sock);
sock:= nil;
@@ -383,7 +383,7 @@
state.buf:= '';
state.l:= 0;
- state.netState:= netConnecting;
+ isConnected:= true;
netReaderThread:= SDL_CreateThread(@netReader, 'netReader', nil);
SDL_DetachThread(netReaderThread)
@@ -392,6 +392,7 @@
procedure initModule;
begin
sock:= nil;
+ isConnected:= false;
SDLNet_Init;
--- a/hedgewars/uFLNetProtocol.pas Sat Dec 05 16:14:59 2015 +0300
+++ b/hedgewars/uFLNetProtocol.pas Sun Dec 06 19:56:33 2015 +0300
@@ -473,6 +473,7 @@
procedure handler_TEAM_ACCEPTED(var p: TCmdParamS);
begin
+ netAcceptedTeam(p.str1)
end;
procedure handler_TEAM_COLOR(var p: TCmdParamSS);
--- a/hedgewars/uFLTeams.pas Sat Dec 05 16:14:59 2015 +0300
+++ b/hedgewars/uFLTeams.pas Sun Dec 06 19:56:33 2015 +0300
@@ -10,8 +10,10 @@
function teamByName(s: shortstring): PTeam;
+procedure sendTeam(var team: TTeam);
+
implementation
-uses uFLUtils, uFLIPC, uPhysFSLayer, uFLData;
+uses uFLUtils, uFLIPC, uPhysFSLayer, uFLData, uFLNet;
const MAX_TEAM_NAMES = 128;
var
@@ -179,4 +181,26 @@
FreeMem(teamsList, sizeof(teamsList^) * teamsNumber)
end;
+procedure sendTeam(var team: TTeam);
+var i: Longword;
+begin
+ with team do
+ begin
+ sendNetLn('ADD_TEAM');
+ sendNetLn(teamName);
+ sendNetLn(IntToStr(color));
+ sendNetLn(grave);
+ sendNetLn(fort);
+ sendNetLn(voice);
+ sendNetLn(flag);
+ sendNetLn(IntToStr(botLevel));
+ for i := 0 to 7 do
+ begin
+ sendNetLn(hedgehogs[i].name);
+ sendNetLn(hedgehogs[i].hat);
+ end;
+ sendNetLn('')
+ end;
+end;
+
end.