Changeset 185 for trunk/UGameServer.pas


Ignore:
Timestamp:
Feb 12, 2018, 3:08:27 PM (7 years ago)
Author:
chronos
Message:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UGameServer.pas

    r184 r185  
    66
    77uses
    8   Classes, SysUtils, UGame, UGameClient, DOM, XMLConf;
     8  Classes, SysUtils, UGame, UGameClient, DOM, XMLConf, fgl, SpecializedList,
     9  UGameProtocol;
    910
    1011type
    1112  TServerMode = (smLocal, smNetworkServer, smNetworkClient);
     13
     14  { TServerClient }
     15
     16  TServerClient = class
     17  private
     18    FOnReceiveCmd: TCommandEvent;
     19    procedure ReceiveCmd(Command: TCommand; DataOut, DataIn: TStream);
     20  public
     21    Game: TGame;
     22    Protocol: TGameProtocolServer;
     23    procedure DoChange;
     24    procedure SendCmd(Command: TCommand; DataOut, DataIn: TStream);
     25    property OnReceiveCmd: TCommandEvent read FOnReceiveCmd write
     26      FOnReceiveCmd;
     27    constructor Create;
     28    destructor Destroy; override;
     29  end;
     30
     31  TServerClients = class(TFPGObjectList<TServerClient>)
     32    Game: TGame;
     33  end;
    1234
    1335  { TServer }
     
    2446    procedure GameStarted(Sender: TObject);
    2547  public
    26     Clients: TClients;
     48    Clients: TServerClients;
    2749    LocalNetworkAddress: string;
    2850    LocalNetworkPort: Word;
     
    4264
    4365implementation
     66
     67{ TServerClient }
     68
     69procedure TServerClient.DoChange;
     70begin
     71
     72end;
     73
     74procedure TServerClient.SendCmd(Command: TCommand; DataOut, DataIn: TStream);
     75begin
     76
     77end;
     78
     79constructor TServerClient.Create;
     80begin
     81  Protocol := TGameProtocolServer.Create;
     82end;
     83
     84destructor TServerClient.Destroy;
     85begin
     86  Protocol.Free;
     87  inherited Destroy;
     88end;
     89
     90procedure TServerClient.ReceiveCmd(Command: TCommand; DataOut, DataIn: TStream);
     91begin
     92  if Assigned(FOnReceiveCmd) then
     93    FOnReceiveCmd(Command, DataOut, DataIn);
     94end;
    4495
    4596{ TServer }
     
    102153procedure TServer.DoChange;
    103154var
    104   Client: TClient;
     155  Client: TServerClient;
    105156begin
    106157  for Client in Clients do
     
    113164begin
    114165  for I := 0 to Clients.Count - 1 do
    115   with TClient(Clients[I]) do begin
    116     View.Clear;
     166  with TServerClient(Clients[I]) do begin
     167    //TODO View.Clear;
    117168  end;
    118169end;
     
    142193procedure TServer.InitClients;
    143194var
    144   Client: TClient;
     195  Client: TServerClient;
    145196  Player: TPlayer;
    146197begin
    147198  Clients.Clear;
    148   Clients.New(SSpectator);
    149 
    150   for Player in Game.Players do
    151   with Player do
    152   if Mode = pmHuman then begin
    153     Clients.New(Player.Name).ControlPlayer := Player;
    154   end;
    155 
    156   for Client in Clients do
    157   with Client do begin
    158     View.Clear;
    159     View.Zoom := 1;
    160     if Assigned(ControlPlayer) and Assigned(ControlPlayer.StartCell) then
    161       View.CenterPlayerCity(ControlPlayer)
    162       else View.CenterMap;
    163   end;
    164199end;
    165200
     
    173208begin
    174209  FGame := nil;
    175   Clients := TClients.Create;
     210  Clients := TServerClients.Create;
    176211end;
    177212
Note: See TracChangeset for help on using the changeset viewer.