📄 pino3srv.dpr
字号:
program pino3srv;
uses Windows,
Classes,
WinSock,
SysUtils,
IniFiles,
actuser in 'actuser.pas',
server in 'server.pas',
admuser in 'admuser.pas',
abstuser in 'abstuser.pas',
// dbgthrd in 'dbgthrd.pas',
misc in 'misc.pas',
room in 'room.pas';
var
WSAData:TWSAData;
WSAResult:Integer;
st:string;
user:^TRegUser;
i2,i,size:Integer;
room:TRoom;
au:TActUser;
fts:Integer;
cts:TDateTime;
{$R *.RES}
{$I ..\..\defines.inc}
function CtrlHandler(dwCtrlType:DWORD):Boolean; stdcall;
var i:Integer;
begin
Writeln('Shutting down');
DeleteFile(cui);
chatserver.Shutdown;
for i:=ActUsers.Count-1 downto 0 do
begin
TActUser(ActUsers.Objects[i]).SendLine(PM_DISCONN,SC_NORMAL,EC_SHUTDOWN,'');
TActUser(ActUsers.Objects[i]).Close;
end;
ExitProcess(0);
end;
begin
Writeln(Format('PINO 3-Server (Build %d)',[Build]));
Writeln('Copyright (C) 1998,1999-2003 alcomp Development');
Writeln;
WSAResult:=WSAStartup(257,WSAData);
if WSAResult<>0 then
begin
Writeln('Could not initialize winsock');
Writeln('Error Code: ',WSAResult);
Halt(WSAResult);
end;
Writeln('Reading configuration');
chatname:=inifile.ReadString(IniSections[1],'Chatname','My PINO Chat');
port:=inifile.ReadInteger(IniSections[1],'Port',1995);
bindto:=inifile.ReadString(IniSections[1],'BindTo','*');
maxrooms:=inifile.ReadInteger(IniSections[1],'Maximum number of user rooms',-1);
cui:=inifile.ReadString(IniSections[1],'CUI file','');
inifile.ReadSectionValues(IniSections[2],sysrooms);
noanos:=inifile.ReadBool(IniSections[3],'Only registered users',false);
maxusers:=inifile.ReadInteger(IniSections[3],'Maximum number of users',0);
regpass:=inifile.ReadInteger(IniSections[3],'Registration password',0);
UserIPs.CommaText:=inifile.ReadString(IniSections[3],'IPList','');
timeout:=inifile.ReadInteger(IniSections[3],'Timeout',15);
adm_pwd:=inifile.ReadInteger(IniSections[4],'Administration password',0);
adm_port:=inifile.ReadInteger(IniSections[4],'Administration port',0);
adm_bindto:=inifile.ReadString(IniSections[4],'BindTo','*');
AdminIPs.CommaText:=inifile.ReadString(IniSections[4],'IPList','');
bannerupdate:=inifile.ReadInteger(IniSections[5],'Update interval',0);
inifile.ReadSectionValues(IniSections[5],banners);
i:=banners.IndexOfName('Update interval'); if i>-1 then banners.Delete(i);
try welcome.LoadFromFile(pinoroot+'WELCOME.TXT'); except Writeln('WARNING: The welcome message file '+pinoroot+'welcome.txt couldn''t be read.'); end;
{$IFNDEF HOME}
{ if (adm_pwd=0)or(adm_port=0) then
begin
Writeln('HINT: No administration settings specified. Please enter them now.');
Writeln;
Write('Please enter the password for the administration server: ');
Readln(st);
adm_pwd:=GetCheckSum(st);
repeat
Write('Please enter the port for the administration server: ');
Readln(st);
adm_port:=StrToIntDef(st,-1);
if (adm_port<1)or(adm_port>65535) then
begin
Writeln('ERROR: ',st,' is an invalid port number.');
Writeln(' Please specify a value between 1 and 65535');
end
until (adm_port>0)and(adm_port<65536);
inifile.WriteInteger(IniSections[4],'Administration Password',adm_pwd);
inifile.WriteInteger(IniSections[4],'Administration Port',adm_port);
end;}
{$ENDIF}
userdb:=CreateFile(PChar(pinoroot+'PINO3SRV.UDB'),GENERIC_READ or GENERIC_WRITE,FILE_SHARE_READ,nil,OPEN_ALWAYS,0,0);
if userdb=INVALID_HANDLE_VALUE then
begin
Writeln('FATAL ERROR: It was not possible to create/open the userdatabase.');
Halt(1);
end;
size:=GetFileSize(userdb,nil);
if size mod soru>0 then
begin
Writeln('FATAL ERROR: The user database appears to be corrupt.');
Writeln(' Please contact alcomp''s support at support@alcomp.net.');
Halt(1);
end;
for i:=1 to size div soru do
begin
New(user);
ReadFile(userdb,user^,soru,i2,nil);
RegUsers.AddObject(user^.nick,Pointer(user));
end;
InitializeCriticalSection(synchronizer);
try
chatserver:=TServer.Create(port,bindto,false);
except
Writeln('Chatserver could not be started (Errorcode: ',LastError,')');
Halt(1);
end;
Writeln('Chatserver is running');
{$IFDEF debug}
{$IFNDEF HOME}
try
{$IFDEF PRO}
// adm_server:=TServer.Create(adm_port,'127.0.0.1',true);
{$ELSE}
// adm_server:=TServer.Create(adm_port,adm_bindto,true);
{$ENDIF}
except
Writeln('Administration server could not be started (Errorcode: ',LastError,')');
Halt(1);
end;
// Writeln('Administration server is running');
{$ENDIF}
{$ENDIF}
i:=FindWindow('TThreadWindow',nil);
if i<>0 then DestroyWindow(i);
SetConsoleCtrlHandler(@CtrlHandler,true);
fts:=GetTickCount;
repeat
cts:=Now;
if timeout>0 then
begin
EnterCriticalSection(synchronizer);
for i:=ActUsers.Count-1 downto 0 do
begin
au:=TActUser(ActUsers.Objects[i]);
if au.Lastact+timeout*0.0006944444<cts then
begin
au.SendLine(PM_DISCONN,SC_NORMAL,EC_TIMEDOUT,'');
au.Close;
end;
end;
LeaveCriticalSection(synchronizer);
end;
if cui<>'' then
begin
i2:=CreateFile(PChar(cui),GENERIC_WRITE,0,nil,CREATE_ALWAYS,0,0);
if i2<>INVALID_HANDLE_VALUE then
begin
st:='';
EnterCriticalSection(synchronizer);
for i:=0 to ActUsers.Count-1 do if TActUser(ActUsers.Objects[i]).Hidden=false then st:=st+ActUsers[i]+' '+TActUser(ActUsers.Objects[i]).Color+#13#10;
LeaveCriticalSection(synchronizer);
WriteFile(i2,st[1],Length(st),i,nil);
st:='';
CloseHandle(i2);
end else Writeln('WARNING: Could not write to CUI file at '+cui);
end;
Sleep(60000);
until false;
end.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -