123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893 |
- unit UNetwork;
- interface
- uses
- Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
- Dialogs, ScktComp, ExtCtrls;
-
- type
- TForm3 = class(TForm)
- Timer3: TTimer;
- ClientSocket: TClientSocket;
- ServerSocket: TServerSocket;
- procedure ClientSocketConnect(Sender: TObject;
- Socket: TCustomWinSocket);
- procedure ClientSocketDisconnect(Sender: TObject;
- Socket: TCustomWinSocket);
- procedure ClientSocketError(Sender: TObject; Socket: TCustomWinSocket;
- ErrorEvent: TErrorEvent; var ErrorCode: Integer);
- procedure SocketRead(Sender: TObject; Socket: TCustomWinSocket);
- procedure ServerSocketClientConnect(Sender: TObject;
- Socket: TCustomWinSocket);
- procedure Timer3Timer(Sender: TObject);
- procedure FormCreate(Sender: TObject);
- procedure FormDestroy(Sender: TObject);
- procedure SendMap(Socket: TCustomWinSocket);
- procedure SendNewID(Socket: TCustomWinSocket);
- procedure SendGoalPos(Socket: TCustomWinSocket);
- procedure RequestNewID(Socket: TCustomWinSocket);
- procedure AddToPlayerArr(ID:Cardinal);
- private
- public
- procedure SendSpeedChange(ID:Cardinal);
- procedure SendRaum(Socket: TCustomWinSocket; RaumPos:TPoint);overload;
- procedure SendRaum(RaumPos:TPoint);overload;
- procedure SendCeilWalk; overload;
- procedure SendCeilWalk(Socket: TCustomWinSocket); overload;
- procedure SendCeilWalk(ID: Cardinal); overload;
- procedure SendCeilWalk(ID: Cardinal; Socket: TCustomWinSocket); overload;
- procedure SendWin(ID: Cardinal); overload;
- procedure SendWin(ID: Cardinal;Socket: TCustomWinSocket); overload;
- procedure SendKill(ID: Cardinal); overload;
- procedure SendKill(ID: Cardinal;Socket: TCustomWinSocket); overload;
- procedure SendJump; overload;
- procedure SendJump(Socket: TCustomWinSocket); overload;
- procedure SendJump(ID: Cardinal); overload;
- procedure SendJump(ID: Cardinal; Socket: TCustomWinSocket); overload;
- procedure SendRaumSorte(Socket: TCustomWinSocket; RaumPos:TPoint); overload;
- procedure SendRaumSorte(RaumPos:TPoint); overload;
- procedure SendRaumSorte(X,Z:Integer); overload;
- procedure SendExplode(X,Z:Integer; Socket: TCustomWinSocket); overload;
- procedure SendExplode(X,Z:Integer); overload;
- procedure SendContaminate(X,Z:Integer);
- procedure SendPosition; overload;
- procedure SendPosition(Socket: TCustomWinSocket); overload;
- procedure SendPosition(ID: Cardinal); overload;
- procedure SendPosition(ID: Cardinal; Socket: TCustomWinSocket); overload;
- procedure SendInkTrigger(ID: Cardinal); overload;
- procedure SendInkTrigger(ID: Cardinal;Socket: TCustomWinSocket); overload;
- end;
-
- var
- Form3:TForm3;
- IDRecieved:Boolean=true;
- Buffer:Ansistring;
- NextObjectToRecieve:Ansistring;
- LastObjectRecieved:Ansistring;
- RoomRecievePos:TPoint;
- MPServerAddress:string='Localhost';
- MPPort:Integer=10808;
- implementation
- uses Unit1, UMaterials,Math,UCreateRaum;
- {$R *.dfm}
- procedure TForm3.AddToPlayerArr(ID:Cardinal);
- var C3:Integer;
- begin
- if ID>=Cardinal(Length(Players)) then setlength(Players,ID+1);
- if ID>=Cardinal(Length(playerarr)) then begin
- Setlength(playerarr,ID+1);
- for C3:=0 to High(playerarr) do
- if not assigned(playerarr[C3])
- then playerarr[C3]:=Form1.NewPlayer(C3);
- end;
- Players[ID].Dead:=false;
- end;
- procedure TForm3.SocketRead(Sender: TObject;
- Socket: TCustomWinSocket);
- var C1,C2,C3,C6,C5:Integer; Data:array of AnsiString;
- P1:PWallset; C4:Byte; S1:AnsiString; B1:Boolean;
- begin
- Buffer:=Buffer+Socket.ReceiveText;
- C2:=0;
- C3:=1;
- for C1:=1 to Length(Buffer) do
- if Buffer[C1]=';' then begin
- Inc(C2);
- Setlength(Data,C2);
- Data[C2-1]:=copy(Buffer,C3,C1-C3);
- C3:=C1+1;
- end;
- S1:=copy(Buffer,C3,Length(Buffer));
- C1:=0;
- try
- while true do begin
- if NextObjectToRecieve='Reload' then begin
- Form1.Reload;
- LastObjectRecieved:=NextObjectToRecieve;
- NextObjectToRecieve:='';
- Continue;
- end;
-
- if NextObjectToRecieve='RequestNewID' then begin
- if ServerSocket.Active then
- SendNewID(Socket);
- LastObjectRecieved:=NextObjectToRecieve;
- NextObjectToRecieve:='';
- Continue;
- end;
- if C1>High(Data) then Break;
- if NextObjectToRecieve='Lightning' then begin
- C2:=strtoint(String(Data[C1]));
- if ServerSocket.Active then SendSpeedChange(C2);
- LastObjectRecieved:=NextObjectToRecieve;
- NextObjectToRecieve:='';
- Continue;
- end;
- if NextObjectToRecieve='PlayerKill' then begin
- C2:=strtoint(String(Data[C1]));
- Players[C2].Dead:=true;
- if ServerSocket.Active then
- SendKill(C2);
-
- LastObjectRecieved:=NextObjectToRecieve;
- NextObjectToRecieve:='';
- C1:=C1+1;
- Continue;
- end;
- if NextObjectToRecieve='GameWin' then begin
- C2:=strtoint(String(Data[C1]));
- Form1.WinGame(C2);
- if ServerSocket.Active then
- SendWin(C2);
- LastObjectRecieved:=NextObjectToRecieve;
- NextObjectToRecieve:='';
- C1:=C1+1;
- Continue;
- end;
- if NextObjectToRecieve='InkTrigger' then begin
- C2:=strtoint(String(Data[C1]));
- Form1.Memo1.Visible:=true;
- if ServerSocket.Active then
- SendInkTrigger(C2);
-
- LastObjectRecieved:=NextObjectToRecieve;
- NextObjectToRecieve:='';
- C1:=C1+1;
- Continue;
- end;
- if NextObjectToRecieve='' then begin
- NextObjectToRecieve:=Data[C1];
- C1:=C1+1;
- Continue;
- end;
- if NextObjectToRecieve='NewID' then begin
- IDRecieved:=true;
- Players[MyID].Dead:=true;
- SendKill(MyID);
-
- MyID:=strtoint(String(Data[C1]));
- AddToPlayerArr(MyID);
- Form1.ChangeSpeedTo(StartSpeed);
- Form1.GLHUDText1.Text:='Speed: '+Floattostr(Round(100*Players[MyID].Speed)/100);
- Form1.GLCamera1.Position.X:=0;
- Form1.GLCamera1.Position.Z:=0;
- Form1.GLCamera1.Up.SetVector(0,1,0);
- PosX:=0;
- PosZ:=0;
- Players[MyID].jumping:=false;
- Players[MyID].X:=0;
- Players[MyID].Y:=0;
- Players[MyID].Z:=0;
- Players[MyID].LastX:=0;
- Players[MyID].LastZ:=0;
- Players[MyID].Ceilwalk:=false;
- Form1.Reload;
- LastObjectRecieved:=NextObjectToRecieve;
- NextObjectToRecieve:='';
- C1:=C1+1;
- Continue;
- end;
- if NextObjectToRecieve='JumpStart' then begin
- C2:=StrToInt(Data[C1]);
- if C2>=Length(Players) then begin
- LastObjectRecieved:=NextObjectToRecieve;
- NextObjectToRecieve:='';
- C1:=C1+1;
- Continue;
- end;
- Form1.startJump(C2);
- if ServerSocket.Active then
- for C3:=0 to ServerSocket.Socket.ActiveConnections-1 do
- if ServerSocket.Socket.Connections[C3]<>Socket then
- SendJump(C2,ServerSocket.Socket.Connections[C3]);
-
- LastObjectRecieved:=NextObjectToRecieve;
- NextObjectToRecieve:='';
- C1:=C1+1;
- Continue;
- end;
- if C1+1>High(Data) then Break;
- if NextObjectToRecieve='ChangeSpeed' then begin
- C3:=Strtoint(Data[C1+1]);
- if not ClientSocket.Active then begin
- LastObjectRecieved:=NextObjectToRecieve;
- NextObjectToRecieve:='';
- C1:=C1+2;
- Continue;
- end;
- Form1.MultiplySpeedBy(sqrt(
- sqr(Players[MyID].X-GoalPos.X*20)
- +sqr(Players[MyID].Z-GoalPos.Y*20))
- /StrToFloat(Data[C1]));
- if Cardinal(C3)<>MyID then begin
- Form1.Panel11.Font.Color:=RGB(255,255,0);
- Form1.Panel11.Color:=RGB(0,0,0);
- Form1.Panel11.Visible:=true;
- Form1.Panel11.Caption:='Speed decreased to '
- +Floattostr(Round(100*Players[MyID].Speed)/100);
- Panel11Seconds:=3;
- Form1.GLHUDText1.Text:='Speed: '
- +Floattostr(Round(100*Players[MyID].Speed)/100);
- end;
- LastObjectRecieved:=NextObjectToRecieve;
- NextObjectToRecieve:='';
- C1:=C1+2;
- Continue;
- end;
- if NextObjectToRecieve='CreateRaum' then begin
- RoomRecievePos.X:=Strtoint(Data[C1]);
- RoomRecievePos.Y:=Strtoint(Data[C1+1]);
- if not Map[RoomRecievePos.X,RoomRecievePos.Y].created then
- CreateRaum(RoomRecievePos.X,RoomRecievePos.Y);
- SendRaum(Socket,RoomRecievePos);
- LastObjectRecieved:=NextObjectToRecieve;
- NextObjectToRecieve:='';
- C1:=C1+2;
- Continue;
- end;
- if NextObjectToRecieve='Explode' then begin
- RoomRecievePos.X:=Strtoint(Data[C1]);
- RoomRecievePos.Y:=Strtoint(Data[C1+1]);
- Form1.Explode(RoomRecievePos.X,RoomRecievePos.Y);
- Form1.Reload;
- if ServerSocket.Active then
- for C3:=0 to ServerSocket.Socket.ActiveConnections-1 do
- if ServerSocket.Socket.Connections[C3]<>Socket then
- SendExplode(RoomRecievePos.X,RoomRecievePos.Y,
- ServerSocket.Socket.Connections[C3]);
-
- LastObjectRecieved:=NextObjectToRecieve;
- NextObjectToRecieve:='';
- C1:=C1+2;
- Continue;
- end;
- if NextObjectToRecieve='Contaminate' then begin
- RoomRecievePos.X:=Strtoint(Data[C1]);
- RoomRecievePos.Y:=Strtoint(Data[C1+1]);
- Form1.SpreadContamination(RoomRecievePos.X,RoomRecievePos.Y);
- LastObjectRecieved:=NextObjectToRecieve;
- NextObjectToRecieve:='';
- C1:=C1+2;
- Continue;
- end;
- if NextObjectToRecieve='GoalPos' then begin
- if not ServerSocket.Active then begin
- GoalPos.X:=Strtoint(String(Data[C1]));
- GoalPos.Y:=Strtoint(String(Data[C1+1]));
- end;
- LastObjectRecieved:=NextObjectToRecieve;
- NextObjectToRecieve:='';
- C1:=C1+2;
- Continue;
- end;
- if NextObjectToRecieve='CeilWalk' then begin
- C2:=strtoint(Data[C1]);
-
- AddToPlayerArr(C2);
- Players[C2].Ceilwalk:=StrToBool(String(Data[C1+1]));
- if ServerSocket.Active then
- for C3:=0 to ServerSocket.Socket.ActiveConnections-1 do
- if ServerSocket.Socket.Connections[C3]<>Socket then
- SendCeilWalk(C2,ServerSocket.Socket.Connections[C3]);
-
- LastObjectRecieved:=NextObjectToRecieve;
- NextObjectToRecieve:='';
- C1:=C1+2;
- Continue;
- end;
- if C1+2>High(Data) then Break;
- if NextObjectToRecieve='RaumSorte' then begin
- RoomRecievePos.X:=Strtoint(String(Data[C1]));
- RoomRecievePos.Y:=Strtoint(String(Data[C1+1]));
- Map[RoomRecievePos.X,RoomRecievePos.Y].Inhalt.Sorte:=
- Strtoint(Data[C1+2]);
- if ServerSocket.Active then
- for C3:=0 to ServerSocket.Socket.ActiveConnections-1 do
- if ServerSocket.Socket.Connections[C3]<>Socket then
- SendRaumSorte(ServerSocket.Socket.Connections[C3],RoomRecievePos);
- C1:=C1+3;
- LastObjectRecieved:=NextObjectToRecieve;
- NextObjectToRecieve:='';
- Form1.ReloadRoom(RoomRecievePos.X,RoomRecievePos.Y);
- Continue;
- end;
- if NextObjectToRecieve='RaumRichtung' then begin
- RoomRecievePos.X:=Strtoint(Data[C1]);
- RoomRecievePos.Y:=Strtoint(Data[C1+1]);
- Map[RoomRecievePos.X,RoomRecievePos.Y].Inhalt.Daten:=
- @Richtungen[TRichtung(Strtoint(Data[C1+2]))];
- Form1.ReloadRoom(RoomRecievePos.X,RoomRecievePos.Y);
-
- C1:=C1+3;
- LastObjectRecieved:=NextObjectToRecieve;
- NextObjectToRecieve:='';
- Continue;
- end;
-
- if C1+3>High(Data) then Break;
- //Spielerposition empfangen
- if NextObjectToRecieve='Position' then begin
- C2:=strtoint(Data[C1]);
- if Cardinal(C2)=MyID then begin
- C1:=C1+4;
- LastObjectRecieved:=NextObjectToRecieve;
- NextObjectToRecieve:='';
- Continue;
- end;
- AddToPlayerArr(C2);
- Players[C2].LastX:=Players[C2].X;
- Players[C2].LastZ:=Players[C2].Z;
- Players[C2].LastTimeStart:=GetTickCount;
- Players[C2].LastTimeEnd:=GetTickCount+Timer3.Interval;
- Players[C2].X:=Strtofloat(String(Data[C1+1]));
- Players[C2].Z:=Strtofloat(String(Data[C1+2]));
- Players[C2].Speed:=Strtofloat(String(Data[C1+3]));
- C1:=C1+4;
- LastObjectRecieved:=NextObjectToRecieve;
- NextObjectToRecieve:='';
- Continue;
- end;
- if C1+5>High(Data) then Break;
- //Raum empfangen
- if NextObjectToRecieve='Raum' then begin
- B1:=GetRT(PosX,PosZ).Contaminate;
- RoomRecievePos.X:=Strtoint(String(Data[C1]));
- RoomRecievePos.Y:=Strtoint(String(Data[C1+1]));
- C4:=Strtoint(String(Data[C1+2]));
- P1:=@C4;
- Map[RoomRecievePos.X,RoomRecievePos.Y].Walls:=P1^;
- C4:=Strtoint(String(Data[C1+3]));
- P1:=@C4;
- Map[RoomRecievePos.X,RoomRecievePos.Y].UpWalls:=P1^;
- C4:=Strtoint(String(Data[C1+4]));
- P1:=@C4;
- Map[RoomRecievePos.X,RoomRecievePos.Y].DownWalls:=P1^;
- Map[RoomRecievePos.X,RoomRecievePos.Y].Inhalt.Sorte:=
- Strtoint(String(Data[C1+5]));
- Map[RoomRecievePos.X,RoomRecievePos.Y].Inhalt.Daten:=nil;
- Map[RoomRecievePos.X,RoomRecievePos.Y].created:=true;
- LastObjectRecieved:=NextObjectToRecieve;
-
- if GetRT(PosX,PosZ).Contaminate and not B1 then begin
- Form1.ChangeSpeedBy(-RandomRange(-50,292)/100);
- Form1.Panel11.Font.Color:=RGB(0,0,0);
- Form1.Panel11.Color:=RGB(249,245,0);
- Form1.Panel11.Visible:=true;
- Form1.Panel11.Caption:='Contamination! Speed decreased to '
- +Floattostr(Round(100*Players[MyID].Speed)/100);
- Panel11Seconds:=3;
- end;
- NextObjectToRecieve:='';
- C1:=C1+6;
- Form1.ReloadRoom(RoomRecievePos.X,RoomRecievePos.Y);
- Continue;
- end;
- LastObjectRecieved:='unknown: '+NextObjectToRecieve;
- NextObjectToRecieve:='';
- end;
- except
- AssignFile(log,'NetworkLog.txt');
- if not FileExists('NetworkLog.txt') then begin
- Rewrite(log);
- Write(log,buffer);
- CloseFile(log);
- end;
- end;
- Buffer:='';
- for C2:=C1 to High(Data) do
- Buffer:=Buffer+Data[C2]+';';
- Buffer:=Buffer+S1;
- end;
- procedure TForm3.ClientSocketConnect(Sender: TObject;
- Socket: TCustomWinSocket);
- var C1,C2:Integer;
- begin
- IDRecieved:=false;
- for C1:=-mapsize to mapsize do
- for C2:=-mapsize to mapsize do Map[C1,C2].created:=false;
- ShowMessage('Connected to Server '+MPServerAddress+':'+Inttostr(MPPort));
- end;
- procedure TForm3.ServerSocketClientConnect(Sender: TObject;
- Socket: TCustomWinSocket);
- begin
- SendNewID(Socket);
- SendMap(Socket);
- SendGoalPos(Socket);
- end;
- procedure TForm3.ClientSocketDisconnect(Sender: TObject;
- Socket: TCustomWinSocket);
- begin
- ShowMessage('Disconnected from Server');
- end;
- procedure TForm3.ClientSocketError(Sender: TObject;
- Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
- var ErrorCode: Integer);
- begin
- if ErrorCode=10061 then begin
- ShowMessage('Server not found');
- ErrorCode:=0;
- end;
- end;
- procedure TForm3.SendExplode(X,Z:Integer; Socket: TCustomWinSocket);
- begin
- Socket.SendText(AnsiString(
- 'Explode;'
- +IntToStr(X)+';'
- +IntToStr(Z)+';'));
- end;
- procedure TForm3.SendExplode(X,Z:Integer);
- var C2:Integer;
- begin
- if ClientSocket.Active then SendExplode(X,Z,ClientSocket.Socket)
- else if ServerSocket.Active then
- for C2:=0 to ServerSocket.Socket.ActiveConnections-1 do begin
- SendExplode(X,Z,ServerSocket.Socket.Connections[C2]);
- end;
- end;
- procedure TForm3.SendContaminate(X,Z:Integer);
- begin
- ClientSocket.Socket.SendText(AnsiString(
- 'Contaminate;'
- +IntToStr(X)+';'
- +IntToStr(Z)+';'));
- end;
- procedure TForm3.SendPosition(Socket: TCustomWinSocket);
- begin
- Socket.SendText(AnsiString(
- 'Position;'
- +intToStr(MyID)+';'
- +FloatToStr(Players[MyID].X)+';'
- +FloatToStr(Players[MyID].Z)+';'
- +FloatToStr(Players[MyID].Speed)+';'));
- end;
- procedure TForm3.SendPosition;
- var C2:Integer;
- begin
- if ClientSocket.Active then SendPosition(ClientSocket.Socket)
- else if ServerSocket.Active then
- for C2:=0 to ServerSocket.Socket.ActiveConnections-1 do begin
- SendPosition(ServerSocket.Socket.Connections[C2]);
- end;
- end;
- procedure TForm3.SendPosition(ID:Cardinal);
- var C2:Integer;
- begin
- if ClientSocket.Active then SendPosition(ID,ClientSocket.Socket)
- else if ServerSocket.Active then
- for C2:=0 to ServerSocket.Socket.ActiveConnections-1 do begin
- SendPosition(ID,ServerSocket.Socket.Connections[C2]);
- end;
- end;
- procedure TForm3.SendPosition(ID:Cardinal; Socket: TCustomWinSocket);
- begin
- Socket.SendText(AnsiString(
- 'Position;'
- +intToStr(ID)+';'
- +FloatToStr(Players[ID].X)+';'
- +FloatToStr(Players[ID].Z)+';'
- +FloatToStr(Players[ID].Speed)+';'));
- end;
- procedure TForm3.Timer3Timer(Sender: TObject);
- var C2:Integer;
- begin
- if (not IDRecieved) and ClientSocket.Active then Exit;
- if ClientSocket.Active then SendPosition
- else if ServerSocket.Active then begin
- for C2:=0 to High(Players) do
- if not Players[C2].Dead then
- SendPosition(C2);
- end;
- end;
- procedure TForm3.FormCreate(Sender: TObject);
- begin
- ServerSocket.Active:=false;
- ClientSocket.Active:=false;
- ClientSocket.Port:=MPPort;
- ServerSocket.Port:=MPPort;
- ClientSocket.Host:=MPServerAddress;
- end;
- procedure TForm3.FormDestroy(Sender: TObject);
- begin
- Timer3.Enabled:=false;
- end;
-
- procedure TForm3.SendMap(Socket: TCustomWinSocket);
- var C1,C2:Integer;RaumPos:TPoint;
- begin
- for C1:=-raumrange to raumrange do
- for C2:=-raumrange to raumrange do
- if Map[C1,C2].created then begin
- RaumPos.X:=C1;
- RaumPos.Y:=C2;
- SendRaum(Socket,RaumPos);
- end;
- end;
- procedure TForm3.SendCeilWalk(Socket: TCustomWinSocket);
- begin
- Socket.SendText( AnsiString(
- 'CeilWalk;'
- +IntToStr(MyID)+';'
- +BoolToStr(players[MyID].CeilWalk)+';'));
- end;
- procedure TForm3.SendCeilWalk;
- var C2:Integer;
- begin
- if ClientSocket.Active then SendCeilWalk(ClientSocket.Socket)
- else if ServerSocket.Active then
- for C2:=0 to ServerSocket.Socket.ActiveConnections-1 do begin
- SendCeilWalk(ServerSocket.Socket.Connections[C2]);
- end;
- end;
- procedure TForm3.SendCeilWalk(ID:Cardinal);
- var C2:Integer;
- begin
- if ClientSocket.Active then SendCeilWalk(ID,ClientSocket.Socket)
- else if ServerSocket.Active then
- for C2:=0 to ServerSocket.Socket.ActiveConnections-1 do begin
- SendCeilWalk(ID,ServerSocket.Socket.Connections[C2]);
- end;
- end;
- procedure TForm3.SendCeilWalk(ID:Cardinal; Socket: TCustomWinSocket);
- begin
- Socket.SendText(AnsiString(
- 'CeilWalk;'
- +IntToStr(ID)+';'
- +BoolToStr(players[ID].CeilWalk)+';'));
- end;
- procedure TForm3.SendJump(Socket: TCustomWinSocket);
- begin
- Socket.SendText( AnsiString(
- 'JumpStart;'
- +IntToStr(MyID)+';'));
- end;
- procedure TForm3.SendJump;
- var C2:Integer;
- begin
- if ClientSocket.Active then SendJump(ClientSocket.Socket)
- else if ServerSocket.Active then
- for C2:=0 to ServerSocket.Socket.ActiveConnections-1 do begin
- SendJump(ServerSocket.Socket.Connections[C2]);
- end;
- end;
- procedure TForm3.SendJump(ID:Cardinal);
- var C2:Integer;
- begin
- if ClientSocket.Active then SendJump(ID,ClientSocket.Socket)
- else if ServerSocket.Active then
- for C2:=0 to ServerSocket.Socket.ActiveConnections-1 do begin
- SendJump(ID,ServerSocket.Socket.Connections[C2]);
- end;
- end;
- procedure TForm3.SendJump(ID:Cardinal; Socket: TCustomWinSocket);
- begin
- Socket.SendText(AnsiString(
- 'JumpStart;'
- +IntToStr(ID)+';'));
- end;
- procedure TForm3.SendKill(ID: Cardinal; Socket: TCustomWinSocket);
- begin
- Socket.SendText(AnsiString(
- 'PlayerKill;'
- +IntToStr(ID)+';'));
- end;
- procedure TForm3.SendKill(ID: Cardinal);
- var C2:Integer;
- begin
- if ClientSocket.Active
- then SendKill(ID,ClientSocket.Socket)
- else if ServerSocket.Active
- then for C2:=0 to ServerSocket.Socket.ActiveConnections-1 do
- SendKill(ID,ServerSocket.Socket.Connections[C2]);
- end;
- procedure TForm3.SendWin(ID: Cardinal; Socket: TCustomWinSocket);
- begin
- Socket.SendText(AnsiString(
- 'GameWin;'
- +IntToStr(ID)+';'));
- end;
- procedure TForm3.SendWin(ID: Cardinal);
- var C2:Integer;
- begin
- if ClientSocket.Active
- then SendWin(ID,ClientSocket.Socket)
- else if ServerSocket.Active
- then for C2:=0 to ServerSocket.Socket.ActiveConnections-1 do
- SendWin(ID,ServerSocket.Socket.Connections[C2]);
- end;
- procedure TForm3.SendInkTrigger(ID: Cardinal; Socket: TCustomWinSocket);
- begin
- Socket.SendText(AnsiString(
- 'InkTrigger;'
- +IntToStr(ID)+';'));
- end;
- procedure TForm3.SendInkTrigger(ID: Cardinal);
- var C2:Integer;
- begin
- if ClientSocket.Active
- then SendInkTrigger(ID,ClientSocket.Socket)
- else if ServerSocket.Active
- then for C2:=0 to ServerSocket.Socket.ActiveConnections-1 do
- SendInkTrigger(ID,ServerSocket.Socket.Connections[C2]);
- end;
- procedure TForm3.SendSpeedChange(ID:Cardinal);
- var C1,C2:Integer; MaxDist:Real;
- begin
- if not ServerSocket.Active then Exit;
- MaxDist:=0;
- for C2:=0 to High(Players) do
- if Cardinal(C2)<>ID then
- if not Players[C2].Dead then
- MaxDist:=Max(MaxDist,
- sqrt(sqr(Players[C2].X-GoalPos.X*20)+sqr(Players[C2].Z-GoalPos.Y*20)));
- MaxDist:=MaxDist*2;
- if ID<>MyID then begin
- Form1.MultiplySpeedBy(sqrt(
- sqr(Players[MyID].X-GoalPos.X*20)
- +sqr(Players[MyID].Z-GoalPos.Y*20))
- /MaxDist);
- Form1.Panel11.Font.Color:=RGB(255,255,0);
- Form1.Panel11.Color:=RGB(0,0,0);
- Form1.Panel11.Visible:=true;
- Form1.Panel11.Caption:='Speed decreased to '
- +Floattostr(Round(100*Players[MyID].Speed)/100);
- Panel11Seconds:=3;
- Form1.GLHUDText1.Text:='Speed: '
- +Floattostr(Round(100*Players[MyID].Speed)/100);
- end;
- for C1:=0 to ServerSocket.Socket.ActiveConnections-1 do
- ServerSocket.Socket.Connections[C1].SendText(Ansistring(
- 'ChangeSpeed;'
- +FloatToStr(MaxDist)+';'
- +FloatToStr(ID)+';'));
- end;
- procedure TForm3.SendRaum(Socket: TCustomWinSocket; RaumPos:TPoint);
- begin
- Socket.SendText(AnsiString(
- 'Raum;'
- +IntToStr(RaumPos.X)+';'
- +IntToStr(RaumPos.Y)+';'
- +IntToStr(Byte(Map[RaumPos.X,RaumPos.Y].Walls))+';'
- +IntToStr(Byte(Map[RaumPos.X,RaumPos.Y].UpWalls))+';'
- +IntToStr(Byte(Map[RaumPos.X,RaumPos.Y].DownWalls))+';'
- +IntToStr(Byte(Map[RaumPos.X,RaumPos.Y].Inhalt.Sorte))+';'));
- if GetRT(RaumPos.X,RaumPos.Y).TurnRandom[Up]
- or GetRT(RaumPos.X,RaumPos.Y).TurnRandom[Down] then
- Socket.SendText(AnsiString(
- 'RaumRichtung;'
- +IntToStr(RaumPos.X)+';'
- +IntToStr(RaumPos.Y)+';'
- +IntToStr(Byte(Map[RaumPos.X,RaumPos.Y].Inhalt.Daten^))+';'));
- end;
- procedure TForm3.SendRaum(RaumPos:TPoint);
- var C2:Integer;
- begin
- if ClientSocket.Active
- then SendRaum(ClientSocket.Socket,RaumPos)
- else if ServerSocket.Active
- then for C2:=0 to ServerSocket.Socket.ActiveConnections-1 do
- SendRaum(ServerSocket.Socket.Connections[C2],RaumPos);
- end;
- procedure TForm3.SendRaumSorte(Socket: TCustomWinSocket; RaumPos:TPoint);
- begin
- Socket.SendText(AnsiString(
- 'RaumSorte;'
- +IntToStr(RaumPos.X)+';'
- +IntToStr(RaumPos.Y)+';'
- +IntToStr(Byte(Map[RaumPos.X,RaumPos.Y].Inhalt.Sorte))+';'));
- end;
- procedure TForm3.SendRaumSorte(RaumPos:TPoint);
- var C2:Integer;
- begin
- if ClientSocket.Active
- then SendRaumSorte(ClientSocket.Socket,RaumPos)
- else if ServerSocket.Active
- then for C2:=0 to ServerSocket.Socket.ActiveConnections-1 do
- SendRaumSorte(ServerSocket.Socket.Connections[C2],RaumPos);
- end;
- procedure TForm3.SendRaumSorte(X,Z:Integer);
- var RaumPos:TPoint;
- begin
- RaumPos.X:=X;
- RaumPos.Y:=Z;
- SendRaumSorte(RaumPos);
- end;
- procedure TForm3.SendNewID(Socket: TCustomWinSocket);
- var C1:Integer;
- begin
- C1:=Length(Players);
-
- AddToPlayerArr(C1);
- Socket.SendText(AnsiString(
- 'NewID;'
- +IntToStr(C1)+';'));
- end;
- procedure TForm3.RequestNewID(Socket: TCustomWinSocket);
- begin
- Socket.SendText(
- 'RequestNewID;');
- end;
- procedure TForm3.SendGoalPos(Socket: TCustomWinSocket);
- begin
- Socket.SendText(AnsiString(
- 'GoalPos;'
- +IntToStr(GoalPos.X)+';'
- +IntToStr(GoalPos.Y)+';'));
- end;
- end.
|