program MounttaSrv;
{$APPTYPE CONSOLE}
uses
Forms,
SysUtils,
IdBaseComponent,
IdComponent,
IdTCPServer,
idcontext,
IdAntiFreezeBase,
IdAntiFreeze,
inifiles,
Variants,
Classes,
keyboard;
type TServer =
class(TIdTCPServer)
Procedure ExecuteSettings;
procedure DBServerConnect(AContext : TIDContext);
procedure DBServerDisconnect(AContext : TIDContext);
procedure DBServerExecute( AContext: TIdContext);
Function RunCommand(cmd,dir:
string):
string;
private
IfEnd :Boolean ;
Clients:Integer;
{ Private-Deklarationen }
public
{ Public-Deklarationen }
end;
var DBServer:TServer;
INI:TIniFile;
InCom2,Sett:TStringlist;
Procedure TServer.ExecuteSettings;
Var I:Integer;
T:TextFile;
S:TStringList;
begin
Sett:=TStringlist.Create;
S:=Tstringlist.Create;
S.LoadFromFile(ExtractFilePath(Paramstr(0))+'
config.ini');
sett.Delimiter:='
,';
Sett.DelimitedText:=s.Text;
for i := 0
to Sett.Count -1
do
begin
if Sett.Strings[i] = '
Mountara_Port'
then
begin
DBServer.DefaultPort:=StrToInt(Sett.Strings[i+1]);
end;
if Sett.Strings[i] = '
Mountara_ListenQueue'
then
begin
DBServer.ListenQueue:=StrToInt(Sett.Strings[i+1]);
end;
if Sett.Strings[i] = '
Mountara_Max_Connections'
then
begin
DBServer.MaxConnections:=StrToInt(Sett.Strings[i+1]);
end;
end;
end;
procedure TServer.DBServerDisconnect(AContext : TIDContext);
begin
DBserver.Clients:=DBserver.Clients-1;
WriteLn('
» A User is Disconnected. ID ( ',AContext.Connection.Greeting.ID,'
)');
WriteLn('
»» Clients Online: ',DBserver.Clients)
end;
procedure TServer.DBServerConnect(AContext : TIDContext);
begin
DBserver.Clients:=DBserver.Clients+1;
WriteLn('
» A User is Connected. ID ( ',AContext.Connection.Greeting.ID,'
)');
WriteLn('
»» Clients Online: ',DBserver.Clients)
end;
Function TServer.RunCommand(cmd,dir:
string):
string;
Var
Ini:Tinifile;
Op,Cm:TStringlist;
begin
Op:=TStringlist.Create;
Op.Delimiter:='
';
Op.DelimitedText:=CMD;
if Op.Strings[0] = '
GET'
then
begin
Op.Delimiter:='
:';
Op.DelimitedText:=CMD;
Ini:=Tinifile.Create(ExtractFilePath(Paramstr(0))+dir+'
\'+Op.Strings[1]+'
.mdb');
Cm:=TStringlist.Create;
Cm.Delimiter:='
:';
Cm.DelimitedText:=Op.Text;
if not ini.SectionExists(Op.Strings[1])
then begin
WriteLn('
» Datenbank Error:'+#13+'
Eintrag konnte nicht gefunden werden! Setzen Sie den eintrag mit dem "SET" befehl.') ;
WriteLn('
»»');
end else
result:=ini.ReadString(Op.Strings[1],Cm.Strings[2],'
');
end else
if Op.Strings[0] = '
SET'
then
begin
Op.Delimiter:='
:';
Op.DelimitedText:=CMD;
Ini:=Tinifile.Create(ExtractFilePath(Paramstr(0))+dir+'
\'+Op.Strings[1]+'
.mdb');
Cm:=TStringlist.Create;
Cm.Delimiter:='
:';
Cm.DelimitedText:=Op.Text;
try
if Cm.Count < 4
then
begin
WriteLn('
» Datenbank Error:'+#13+'
Kein oder Falsch angegebener wert.') ;
WriteLn('
»»');
Exit;
end else
ini.WriteString(Op.Strings[1],Cm.Strings[2],Cm.Strings[3]);
finally
WriteLn('
» Datenbank: eintrag '+ Cm.Strings[2]+'
'+Cm.Strings[3]+'
in '+Cm.Strings[1]+'
war erfolgreich.');
WriteLn('
»»');
end;
end else
begin
WriteLn('
» Datenbank Error:'+#13+'
Solchein befehl ist mir nicht bekannt.');
WriteLn('
»»');
end;
ini.free;
end;
procedure TServer.DBServerExecute( AContext: TIdContext);
Var S,Player:
String;
Val:Integer;
sVal:
String;
begin
if AContext.Connection.Connected
then
begin
InCom2.DelimitedText:=AContext.Connection.IOHandler.ReadLn();
// START
// AContext.Connection.Socket.
Player:=IntToStr(AContext.Connection.Greeting.
Index);
s:='
SET ONLINEUSER:ENTRYS:1';
RunCommand(S,'
share\users');
If InCom2.Strings[0] = '
GETENTRYS'
then
begin
AContext.Connection.IOHandler.WriteLn('
OnlinePlayers,'+Player);
end else
If InCom2.Strings[0] = '
GETPOSX'
then
begin
S:='
GET ONLINEUSER:POSX'+InCom2.Strings[1];
sval:=RunCommand(S,'
share\users');
AContext.Connection.IOHandler.WriteLn('
POSX,'+sval);
end else
If InCom2.Strings[0] = '
GETPOSY'
then
begin
S:='
GET ONLINEUSER:POSY'+InCom2.Strings[1];
sval:=RunCommand(S,'
share\users');
AContext.Connection.IOHandler.WriteLn('
POSY,'+sval);
end else
If InCom2.Strings[0] = '
GETPOSZ'
then
begin
S:='
GET ONLINEUSER:POSZ'+InCom2.Strings[1];
sval:=RunCommand(S,'
share\users');
AContext.Connection.IOHandler.WriteLn('
POSZ,'+sval);
end;
If InCom2.Strings[0] = '
SETPOSX'
then
begin
S:='
SET ONLINEUSER:POSX1:'+InCom2.Strings[1];
sval:=RunCommand(S,'
share\users');
end;
If InCom2.Strings[0] = '
SETPOSY'
then
begin
S:='
SET ONLINEUSER:POSY1:'+InCom2.Strings[1];
sval:=RunCommand(S,'
share\users');
end;
If InCom2.Strings[0] = '
SETPOSZ'
then
begin
S:='
SET ONLINEUSER:POSZ1:'+InCom2.Strings[1];
sval:=RunCommand(S,'
share\users');
end;
END;
end;
Procedure CreateServ;
Var i:Integer;
begin
WriteLn('
»» ----------------------------------------------------------------');
WriteLn('
»»','
PSDsoft Productions: 2007 - 2009. ');
WriteLn('
»» ----------------------------------------------------------------');
WriteLn('
»»');
WriteLn('
»» ',Application.Title);
WriteLn('
»»');
InCom2:=TStringlist.Create;
DBServer:=TServer.Create(
nil);
DBServer.OnExecute:=DBServer.DBServerExecute;
DBServer.OnDisconnect:=DBServer.DBServerDisconnect;
DBServer.OnConnect:=DBServer.DBServerConnect;
DBserver.Clients:=0;
InCom2.Delimiter:='
,';
try
DBServer.ExecuteSettings;
except
WriteLn('
»» Error: Config - File is Missing.');
Exit;
end;
WriteLn('
»» Set Server Port: ',IntToStr(DBServer.DefaultPort));
Sleep(20);
try
DBServer.Active:=true;
Sleep(20);
finally
if DBServer.Active
then
WriteLn('
»» Set Server Start ....');
WriteLn('
»»');
WriteLn('
»» Clients: ',DBserver.Clients);
end;
end;
var Key:
String;
begin
Application.Title:='
Mounttara World Server';
try
try
CreateServ;
finally
key:=keyboard.VirtualKeyCodeToKeyName(keyboard.KeyPressed());
repeat
ReadLn;
until not true
end;
except
on E:
Exception do
Writeln(E.Classname, '
: ', E.
Message);
end;
end.