0 Members and 1 Guest are viewing this topic.
const//DrużynyALPHA = 1;BRAVO = 2;CHARLIE = 3;DELTA = 4;SPECTATOR = 5;//Gry trybyDEATHMATCH = 0;POINTMATCH = 1;TEAMMATCH = 2;CTF = 3;RAMBO = 4;INF = 5;HTF = 6;//BronieDEAGLES = 1;HKMP5 = 2;AK74 = 3;STEYR = 4;SPAS = 5;RUGER = 6;M79 = 7;BARRET = 8;MINIMI = 9;MINIGUN = 10;FLAMER = 11;BOW = 12;FLAMEBOW = 13;SOCOM = 0;KNIFE = 14;CHAINSAW = 15;LAW = 16;MAXTEAMS = 5;MAXPLAYER = 16; //Maxymalna ilość graczyPLAYER_STATS_ON=1; //Włacz statystyki//GłosowanieProcent = 70; //Ilość głosów potrzebna do przegłosowaniaInitTime = 30; //Czas głosowaniaAddTime = 7; //Dodaj czas gdy ktoś głosuje //Zmiennevarnickname_Password, nickname_IP: array [1..MAXPLAYER] of string;nickname_Name: array [1..MAXPLAYER] of string;oldPassword, newPassword, newPassword2: array [1..MAXPLAYER] of string;nickStatus: array [1..MAXPLAYER] of integer;GOOD: longint;BAD: longint;kickTimer: array [1..MAXPLAYER] of integer;startKickTimer: array [1..MAXPLAYER] of integer;voted: array[1..MAXPLAYER] of boolean;Response: String;ResponseLines: TStringArray;i: integer;playerstats, update: String;Time: integer;//Arrayhighfunction arrayHi( tester: TStringArray ): integer;begin result := GetArrayLength( tester ) - 1;end;//Xsplitfunction xsplit(const source: string; const delimiter: string):TStringArray;var i,x,d:integer; s:string;begin d:=length(delimiter); x:=0; i:=1; SetArrayLength(Result,1); while(i<=length(source)) do begin s:=Copy(source,i,d); if(s=delimiter) then begin i:=i+d; inc(x,1); SetArrayLength(result,x+1); end else begin result[x]:= result[x]+copy(s,1,1); inc(i,1); end; end; if Result[ArrayHi(Result)]='' then SetArrayLength(result,x);end;//Ezplodefunction Explode(Source: string; const Delimiter: string): array of string;var Position, DelLength, ResLength: integer;begin DelLength := Length(Delimiter); Source := Source + Delimiter; repeat Position := Pos(Delimiter, Source); SetArrayLength(Result, ResLength + 1); Result[ResLength] := Copy(Source, 1, Position - 1); ResLength := ResLength + 1; Delete(Source, 1, Position + DelLength - 1); until (Position = 0); SetArrayLength(Result, ResLength - 1);end;//Załaduj ustawieniafunction LoadSettings(File: string): boolean; begin try playerstats := ReadINI(File,'Settings','PlayerStats.php',' '); update := ReadINI(File,'Settings','update.php',' ');except Result := true; exit; end; end; //Uruchomienie serweraprocedure ActivateServer();var b: byte;begin//Uruchom ładowanie ustawieńif LoadSettings('scripts/'+ ScriptName + '/settings.ini') then WriteLn(' [*] '+ ScriptName + ' -> Error while loading settings') else WriteLn(' [*] '+ ScriptName + ' -> Settings loaded successfully');//Tutaj edytuj kolorki :)GOOD := $EE00FF00;BAD:= $ff0033;//Ustaw wszystkie zmienne 0for b := 1 to MAXPLAYER do begin nickStatus[b] := 0; nickname_Name[b] := ''; nickname_Password[b] := ''; nickname_IP[b] := ''; oldPassword[b] := ''; newPassword[b] := ''; newPassword2[b] := ''; kickTimer[b] := 15; startKickTimer[b] := 0; end;end;//AppOnidleprocedure AppOnIdle(Ticks: integer);var b: byte;beginfor b := 1 to MAXPLAYER dobegin if startKickTimer[b] = 1 then begin kickTimer[b] := kickTimer[b] - 1; if kickTimer[b] = 0 then begin WriteConsole(b,'You need to register your nickname!',BAD); kickPlayer(b); startKickTimer[b] := 0; end; end; end;end;//Filterfunction filterFilename(filename: string):string;var i,len: byte; c: string;beginlen := length(filename);result := '';for i := 1 to len dobegin c := copy(filename,i,1); if (c=chr(92)) or (c='/') or (c='\') or (c=':') or (c='*') or (c='?') or (c='"') or (c='<') or (c='>') or (c='|') or (c='.') then result := result + '_' else result := result + c; end;end;//Ładuj profilfunction loadNickname(nick: string; ID: byte): string;var temparray: TStringArray; fileData,fileName: string;begin//Filtruj nazwę graczafileName := filterFileName( nick );//Sprawdź czy profil istnieje i załadujif FileExists('nickreg/'+filename+'.txt') = true then begin filedata := ReadFile('nickreg/'+filename+'.txt') //Podziel profil xsplit temparray := xsplit(filedata,chr(13)+chr(10)); nickname_Name[ID] := temparray[0]; nickname_Password[ID] := temparray[1]; nickname_IP[ID] := temparray[2]; result := nickname_Password[ID];end elsebegin //Jeśli profil nie istnieje poproś gracza o jego założenie i zresetuj zmienne. WriteConsole(ID,'The nickname '+GetPlayerStat(ID,'name')+' is not registered!',GOOD); WriteConsole(ID,'To protect your nickname type: /create <yourpasswordhere>',GOOD); nickStatus[ID] := 0; nickname_Name[ID] := ''; nickname_Password[ID] := ''; nickname_Ip[ID] := ''; result := '';end;end; //Zapisz profilprocedure SaveNickname(name,password,ip: string; currentDate:string; ID: byte);var filename,outdata: string;begin//Filter nazwy graczyfilename := FilterFilename(name);//Sprawdź czy taki nick istniejeif FileExists('nickreg/'+filename+'.txt') = true then begin WriteConsole(ID,'Nickname already exists!',BAD);end else begin currentDate := FormatDate('dd:mm:yy'); //Ustaw dane do zapisu outdata := name+chr(13)+chr(10)+ password+chr(13)+chr(10)+ ip+chr(13)+chr(10)+ currentDate+chr(13)+chr(10); //Zapisz nowy profil WriteFile('nickreg/'+filename+'.txt',outdata);end;end;//Aktualizuj profilprocedure UpdateNickname(nick: string; ID: byte);var temparray: TStringArray; outdata: string; fileName, fileData: string; ip, currentDate: string;beginfilename := FilterFilename(nick);if getPlayerStat( ID, 'Active' ) then begin //Jeśli nick istnieje filedata := ReadFile('nickreg/'+filename+'.txt'); //Sprawdź czy gracz jest zalogowany if nickStatus[ID] = 1 then begin //Sprawdz czy plik nie jest pusty if filedata <> '' then begin //Xsplit temparray := xsplit(filedata,chr(13)+chr(10)); Nickname_IP[ID] := temparray[2]; //Uzyskaj ip gracza i date ip := getPlayerStat( ID, 'ip'); currentDate := FormatDate('dd:mm:yy'); //Ustaw dane do zapisu outdata := nickname_Name[ID]+chr(13)+chr(10)+ Nickname_Password[ID]+chr(13)+chr(10)+ ip+chr(13)+chr(10)+ currentDate+chr(13)+chr(10); //Zaktualizuj profil gracza WriteFile('nickreg/'+filterFileName(nickname_Name[ID])+'.txt',outdata); end else begin //Jeśli dane z profilu były puste wyczyść dane Nickname_Name[ID] := ''; Nickname_Password[ID] := ''; Nickname_IP[ID] := ''; end; end else begin Writeln('Player did not login for stats!'); end;end;end;//Komendy adminafunction OnCommand(ID: Byte; Text: string): boolean;begin Result := false; end;//Komenty graczafunction OnPlayerCommand(ID: Byte; Text: string): boolean;var inputNick, tempNick, InputPassword, MD5, InputPasswordLogin, nick: string; currentDate: string;begin//Stwórz nowe kontoif (Copy(Text,1,8) = '/create ') then begin //Sprawdź czy gracz jest zalogowany if nickStatus[ID] = 0 then begin //Sprawdź czy gracz jest aktywny if GetPlayerStat(ID, 'Active') = true then begin //Uzyskaj nick nick := GetPlayerStat(ID,'name'); //Sprawdź czy gracz ma już konto if FileExists('nickreg/'+filterFileName(nick)+'.txt') = false then begin //Uzyskaj hasło z tekstu InputPassword := Text; delete(InputPassword,1,8); MD5 := MD5String(inputPassword); //Jeśli pole puste if InputPassword <> '' then begin //Sprawdź długość hasła if length(inputPassword) < 17 then begin //Uzyskaj aktualną datę currentDate := FormatDate('hh:nn:ss am/pm'); //Zapisz nowe konto do pliku SaveNickname(GetPlayerStat(ID,'name'),MD5,GetPlayerStat(ID,'ip'),currentDate, ID); WriteConsole(ID,'Nickname ' + GetPlayerStat(ID,'name') + ' successfully registered!',GOOD); WriteConsole(ID,'Your password is ' + InputPassword + ' - do not forget it!',GOOD); WriteConsole(ID,'To prove that you really are later, use "/login ' + InputPassword + '" to login.',GOOD); WriteLn('NickReg: ' + GetPlayerStat(ID,'name') + ' registered from ' + GetPlayerStat(ID,'ip')); //Zaloguj nowego użytkownika i wyłącz kick timer nickStatus[ID] := 1; startKickTimer[ID] := 0; end else begin WriteConsole(ID,'Max length password is 16 characters!',BAD); end; end else begin WriteConsole(ID,'No password found. Please try again.',BAD); end; end else begin WriteConsole(ID,'You are already a registered user!',BAD); end; end;end;end;//Zmiana hasłaif (Copy(Text,1,12) = '/changepass ') then begin //Sprawdź czy gracz jest zalogowany if nickStatus[ID] = 1 then begin //Sprawdź czy gracz jest aktywny if GetPlayerStat(ID, 'Active') = true then begin //Uzyskaj nick nick := GetPlayerStat(ID,'name'); //Sprawdź czy gracz ma już konto if FileExists('nickreg/'+filterFileName(nick)+'.txt') = true then begin //Uzyskaj hasło z tekstu InputPassword := Text; delete(InputPassword,1,12); //Uzyskaj stare i nowe hasło oldPassword[ID] := MD5String(GetPiece(InputPassword,' ',0)); newPassword[ID] := MD5String(GetPiece(InputPassword,' ',1)); newPassword2[ID] := GetPiece(InputPassword,' ',1); //Sprawdź czy stare hasło jest poprawne if oldPassword[ID] = nickName_Password[ID] then begin //Sprawdź długość nowego hasła if length(newPassword2[ID]) < 17 then begin //Ustaw nowe hasło dla ID nickName_Password[ID] := newPassWord[ID]; //Zapisz nowe hasło UpdateNickname(GetPlayerStat(ID,'name'),ID); WriteConsole(ID,'Password changed to: '+newPassword2[ID],GOOD); end else begin WriteConsole(ID,'Max length password is 16 characters!',BAD); end; end else begin WriteConsole(ID,'Wrong password!',BAD); end; end else begin WriteConsole(ID,'No profile found!',BAD); end; end; end else begin WriteConsole(ID,'Please login first!',BAD); end;end;//Zmiana nickuif (Copy(Text,1,12) = '/changenick ') then begin //Sprawdź czy gracz jest zalogowany if nickStatus[ID] = 1 then begin //Sprawdź czy gracz jest aktywny if GetPlayerStat(ID, 'Active') = true then begin //Uzyskaj nick nick := GetPlayerStat(ID,'name'); //Sprawdź czy gracz już ma konto if FileExists('nickreg/'+filterFileName(nick)+'.txt') = true then begin //Pobierz jego nick i hasło z tekstu InputNick := Text; delete(InputNick,1,12); //Sprawdź czy hasło jest poprawne if nickName_Password[ID] = MD5String(GetPiece(InputNick,' ',0)) then begin //Sprawdź długość nowego nicku if length(GetPiece(InputNick,' ',1)) < 25 then begin //Ustaw nowy nick dla ID i sprawdź czy nowy nick jest zajęty tempNick := GetPiece(InputNick,' ',1); if FileExists('nickreg/'+filterFileName(tempNick)+'.txt') = false then begin //Ustaw nowy nick dla ID nickName_Name[ID] := GetPiece(InputNick,' ',1); //Zapisz zmiane w pliku i wyślij informację o poprawnej zmianie UpdateNickname(GetPlayerStat(ID,'name'),ID); WriteConsole(ID,'NickName changed to: '+nickName_Name[ID],GOOD); WriteConsole(ID,'Please rejoin the server with your new nick to load your new profile',GOOD); end else begin WriteConsole(ID,'That nickname is already taken!',BAD); end; end else begin WriteConsole(ID,'Nickname is over 24 characters, please pick another',BAD); end; end else begin WriteConsole(ID,'Wrong Password!',BAD); end; end else begin WriteConsole(ID,'No profile found!',BAD); end; end; end else begin WriteConsole(ID,'Please login first!',BAD); end;end;//Logowanieif (Copy(Text,1,7) = '/login ') then begin //Sprawdź czy gracz jest zalogowany if (nickStatus[ID] = 0) then begin //Sprawdź czy gracz jest aktywny if GetPlayerStat(ID, 'Active')= true then begin //Uzyskaj nick nick := getPlayerStat(ID, 'Name' ); if FileExists('nickreg/'+filterFileName(nick)+'.txt') = true then begin //Uzyskaj hasło z tekstu InputPasswordLogin := Text; delete(InputPasswordLogin,1,7); //Sprawdź czy hasło jest poprawne if MD5String(InputPasswordLogin) = Nickname_Password[ID] then begin //Zaloguj i wyłącz kicktimer nickStatus[ID] := 1; WriteConsole(ID,'You are now logged in!',GOOD); startKickTimer[ID] := 0; end else begin WriteConsole(ID,'Wrong password.',BAD); end; end else begin WriteConsole(ID,'No profile found!',BAD); end; end; end else begin WriteConsole(ID,'You are already logged in!',BAD); end;end;//Wylogujif Text = '/logout' then begin //Sprawdź czy gracz jest zalogowany if (nickStatus[ID] = 1) then begin WriteConsole(ID,'You have been logged out!',GOOD); WriteConsole(ID,'Type /login ''password'' to login.',GOOD); //Ustaw status gracza na wylogowany nickStatus[ID] := 0; end else begin WriteConsole(ID,'Already logged out!',BAD); end;end;Result := false; end;procedure OnMapChange(NewMap: String);begin//Aktualizacja statystykGetURL(update);WriteConsole(0,'Stats update!',GOOD)end;//Komendy ! graczaprocedure OnPlayerSpeak(ID: byte; Text: string);varnick: string;i,Total: integer;begin//Informacjeif (copy(Text,1,9) = '!reginfo') then begin WriteConsole(ID,'Commands are: /create <password>, /login <password>, /logout',GOOD); WriteConsole(ID,'/changepass <old password> <newpas bsword>, /changenick <password> <newnick>',GOOD); WriteConsole(ID,'!login for example will display info how to login',GOOD);end;//Logowanieif (copy(Text,1,6) = '!login') then begin WriteConsole(ID,'Type /login ''your password'' to login',GOOD);end;//Wylogowanieif (copy(Text,1,7) = '!logout') then begin WriteConsole(ID,'Type /logout ''your password'' to logout',GOOD);end;//Zmiana hasłąif (copy(Text,1,11) = '!changepass') then begin WriteConsole(ID,'Type /changepass ''old password'' ''new password'' to set a new password',GOOD);end;//Zmiana nickuif (copy(Text,1,11) = '!changenick') then begin WriteConsole(ID,'Type /changenick ''your password'' ''new nickname'' to set a new nickname',GOOD);end;//Wczytanie statystykif((Text='!stats')and(PLAYER_STATS_ON=1)) then begin//Uzyskaj nicknick := getPlayerStat(ID, 'Name' ); //Sprawdź czy gracz ma konto if FileExists('nickreg/'+filterFileName(nick)+'.txt') = true then begin //Jeśli zarejstrowany if nickStatus[ID] = 1 then begin Response:= GetURL(playerstats+'?name='+HTTPEncode(GetPlayerStat(ID,'Name'))); ResponseLines:= Explode(Response,chr(13)); for i:=0 to ArrayHigh(ResponseLines) do WriteConsole(0,ResponseLines[i],GOOD); end else begin //Jeśli zarejstrowany a nie zalogowany WriteConsole(ID,'Login to see the stats!',BAD); end; end else begin //Jeśli nie zarejstrowany Response:= GetURL(playerstats+'?name='+HTTPEncode(GetPlayerStat(ID,'Name'))); ResponseLines:= Explode(Response,chr(13)); for i:=0 to ArrayHigh(ResponseLines) do WriteConsole(0,ResponseLines[i],GOOD); WriteConsole(ID,'To protect your stats, register now!',BAD); end;end;if (LowerCase(Text) = '!voteupdate') then begin if Voted[ID] then WriteConsole(ID, 'You have already voted.', BAD) else if (Time = 0) then Time := InitTime else Time := Time + Addtime; Voted[ID] := true; for i := 1 to MAXPLAYER do if (GetPlayerStat(i, 'Active') = true) and (Voted[i]) then Total := Total + 1; if (100 * Total / NumPlayers >= Procent) then begin for i := 1 to MAXPLAYER do Voted[ID] := false; WriteConsole(0, 'Voting for updating statistics, passed.', GOOD); GetURL(update); WriteConsole(0,'Stats update!',GOOD) end else WriteConsole(0,FloattoStr(RoundTo(100 * Total / NumPlayers, 1)) + '% / ' + InttoStr(Procent) + '% required for a vote pass', GOOD); end;end;//Dołączenie do drużynyprocedure OnJoinTeam(ID, Team: byte);begin //Sprawdź czy gracz jest aktywnyif getPlayerStat( ID, 'Active' ) = true then begin //Wurzuć gracza którego nick ma więcej niż 24 znaki if length(getPlayerStat( ID, 'name' )) > 24 then begin WriteConsole(ID,'...your name is over 24 characters, please change it.',BAD); KickPlayer(ID); end; //Załaduj profil gracza LoadNickname(FilterFilename(GetPlayerStat(ID,'name')),ID); //Sprawdź ip gracza if nickname_IP[ID] <> '' then begin if (getPlayerStat( ID, 'ip' )) = nickname_IP[ID] then begin //Autologin for ip nickStatus[ID] := 1; WriteConsole(ID,'Welcome back '+GetPlayerStat(ID,'name')+' (IP: '+GetPlayerStat(ID,'ip')+')',GOOD); startKickTimer[ID] := 0; end else begin nickStatus[ID] := 0; WriteConsole(ID,'The nickname '+GetPlayerStat(ID,'name')+' is REGISTERED!',BAD); WriteConsole(ID,'Use "/login password" to login or you will be kicked in 15 seconds', BAD); startKickTimer[ID] := 1; kickTimer[ID] := 15; end; end; end;end;//Wyjście z gryprocedure OnLeaveGame(ID, Team: byte; Kicked: boolean);begin //Usuń wszystkie zmienne gracza nickStatus[ID] := 0; nickname_Name[ID] := ''; nickname_Password[ID] := ''; nickname_IP[ID] := ''; oldPassword[ID] := ''; newPassword[ID] := ''; newPassword2[ID] := ''; startKickTimer[ID] := 0;end;