Changeset 196 for trunk/UServerList.pas


Ignore:
Timestamp:
May 16, 2018, 9:56:24 AM (6 years ago)
Author:
chronos
Message:
  • Added: Allow to manage list of servers where to connect as client.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/UServerList.pas

    r180 r196  
    66
    77uses
    8   Classes, SysUtils, contnrs;
     8  Classes, SysUtils, fgl, XMLConf;
    99
    1010type
     11
     12  { TServerInfo }
     13
    1114  TServerInfo = class
    1215    Name: string;
     
    1821    MapName: string;
    1922    Latency: TTime;
     23    constructor Create;
    2024  end;
    2125
    22   TServerInfos = class(TObjectList)
     26  TServerInfos = class(TFPGObjectList<TServerInfo>)
    2327  end;
    2428
     
    3135    constructor Create;
    3236    destructor Destroy; override;
     37    procedure LoadConfig(Config: TXmlConfig; Path: string);
     38    procedure SaveConfig(Config: TXmlConfig; Path: string);
    3339  end;
    3440
     41
    3542implementation
     43
     44uses
     45  UGameServer;
     46
     47{ TServerInfo }
     48
     49constructor TServerInfo.Create;
     50begin
     51  Port := DefaultServerPort;
     52end;
    3653
    3754{ TServerList }
     
    4865end;
    4966
     67procedure TServerList.LoadConfig(Config: TXmlConfig; Path: string);
     68var
     69  I: Integer;
     70  Server: TServerInfo;
     71begin
     72  Items.Clear;
     73  Items.Count := Config.GetValue(UnicodeString(Path + '/Count'), 0);
     74  for I := 0 to Items.Count - 1 do begin
     75    Server := TServerInfo.Create;
     76    Server.Name := string(Config.GetValue(UnicodeString(Path + '/Item' + IntToStr(I) + '/Name'), ''));
     77    Server.Address := string(Config.GetValue(UnicodeString(Path + '/Item' + IntToStr(I) + '/Address'), ''));
     78    Server.Port := Config.GetValue(UnicodeString(Path + '/Item' + IntToStr(I) + '/Port'), 0);
     79    Items[I] := Server;
     80  end;
     81end;
     82
     83procedure TServerList.SaveConfig(Config: TXmlConfig; Path: string);
     84var
     85  I: Integer;
     86  Server: TServerInfo;
     87begin
     88  Config.SetValue(UnicodeString(Path + '/Count'), Items.Count);
     89  for I := 0 to Items.Count - 1 do begin
     90    Server := Items[I];
     91    Config.SetValue(UnicodeString(Path + '/Item' + IntToStr(I) + '/Name'), UnicodeString(Server.Name));
     92    Config.SetValue(UnicodeString(Path + '/Item' + IntToStr(I) + '/Address'), UnicodeString(Server.Address));
     93    Config.SetValue(UnicodeString(Path + '/Item' + IntToStr(I) + '/Port'), Server.Port);
     94  end;
     95end;
     96
    5097end.
    5198
Note: See TracChangeset for help on using the changeset viewer.