29.04.2010, 13:59
Код:
#include <a_samp> #include <dudb> #define COLOR_GRAD1 0xB4B5B7FF #define COLOR_GRAD2 0xBFC0C2FF #define COLOR_GRAD3 0xCBCCCEFF #define COLOR_GRAD4 0xD8D8D8FF #define COLOR_GRAD5 0xE3E3E3FF #define COLOR_GRAD6 0xF0F0F0FF #define COLOR_LIGHTBLUE 0x33CCFFAA #define COLOR_GREY 0xAFAFAFAA #define COLOR_PINK 0xFF008096 #define COLOR_BLUE 0x0000FFFF #define COLOR_GREEN 0x00A80096 #define COLOR_RED 0xFF0000AA #define COLOR_ORANGE 0xFF800096 #define COLOR_CYAN 0xFF808096 #define COLOR_YELLOW 0xFFFF00AA #define COLOR_WHITE 0xFFFFFFAA #define COLOR_FADE1 0xE6E6E6E6 #define COLOR_FADE2 0xC8C8C8C8 #define COLOR_DARKBLUE 0x0000A096 #define COLOR_BLACK 0x00000096 #define COLOR_DARKGOLD 0x80800096 #define COLOR_FADE3 0xAAAAAAAA #define COLOR_FADE4 0x8C8C8C8C #define COLOR_FADE5 0x6E6E6E6E #define COLOR_PURPLE 0xFF00FF96 #define COLOR_BROWN 0x80400096 #define COLOR_DBLUE 0x2641FEAA #define COLOR_ALLDEPT 0xFF8282AA new logged[MAX_PLAYERS]; new adminlevel[MAX_PLAYERS]; new money[MAX_PLAYERS]; new playername[MAX_PLAYER_NAME]; new adminname[MAX_PLAYER_NAME]; new score[MAX_PLAYERS]; new string[256]; new cmd[256],tmp[256], tmp2[256]; new idx; forward OnPlayerLogin(playerid,const string[]); main() { } public OnGameModeInit() { return 1; } public OnPlayerRequestClass(playerid, classid) { return 1; } public OnPlayerConnect(playerid) { logged[playerid] = 0; return 1; } public OnPlayerDisconnect(playerid, reason) { GetPlayerName(playerid, playername, sizeof(playername)); money[playerid] = GetPlayerMoney(playerid); score[playerid] = GetPlayerScore(playerid); dini_IntSet(udb_encode(playername), "money", money[playerid]); dini_IntSet(udb_encode(playername), "score", score[playerid]); dini_IntSet(udb_encode(playername), "adminlevel", adminlevel[playerid]); logged[playerid] = 0; return 1; } public OnPlayerSpawn(playerid) { if(logged[playerid] == 0) { SendClientMessage(playerid, COLOR_RED, "You are not logged in yet! USAGE: /login [password]!"); } return 1; } public OnPlayerCommandText(playerid, cmdtext[]) { cmd = strtok(cmdtext, idx); GetPlayerName(playerid, playername, sizeof(playername)); if(strcmp(cmd, "/register", true) == 0) { tmp = strtok(cmdtext, idx); if(!strlen(tmp)) { SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /register (password)"); } else { if (!dini_Exists(udb_encode(playername))) { dini_Create(udb_encode(playername)); dini_IntSet(udb_encode(playername), "password", udb_hash(tmp)); dini_IntSet(udb_encode(playername), "adminlevel", 0); dini_IntSet(udb_encode(playername), "money", 0); dini_IntSet(udb_encode(playername), "score", 0); format(string, sizeof(string), "Account %s has been made! You can now login with the password: %s.", playername, tmp); SendClientMessage(playerid, COLOR_GREEN, string); } else { format(string, sizeof(string), "%s is already registered.", playername,tmp); SendClientMessage(playerid, COLOR_RED, string); } } return 1; } if(strcmp(cmd, "/login", true) == 0) { if(logged[playerid] == 1) { SendClientMessage(playerid, COLOR_RED, "You are already logged in!"); return 1; } tmp = strtok(cmdtext, idx); if(!strlen(tmp)){ SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /login (password)"); } else { if (dini_Exists(udb_encode(playername))) { tmp2 = dini_Get(udb_encode(playername), "password"); if (udb_hash(tmp) != strval(tmp2)) { SendClientMessage(playerid, COLOR_RED, "Wrong password"); } else { logged[playerid] = 1; money[playerid] = dini_Int(udb_encode(playername), "money"); score[playerid] = dini_Int(udb_encode(playername), "score"); adminlevel[playerid] = dini_Int(udb_encode(playername), "adminlevel"); format(string, sizeof(string), "%s, You are now logged in. Your adminlevel is %d, Your money is %d, and your score is %d.", playername, adminlevel[playerid], money[playerid], score[playerid]); SendClientMessage(playerid, COLOR_GREEN, string); GivePlayerMoney(playerid, money[playerid]); SetPlayerScore(playerid, score[playerid]); return 1; } } else { format(string, sizeof(string), "The account %s does not exist yet. Type /register [password] to make an account.", playername); SendClientMessage(playerid, COLOR_RED, string); return 1; } } } if(strcmp(cmd, "/makeadmin", true) == 0) { if(adminlevel[playerid] == 7) { if(logged[playerid] == 1) { tmp = strtok(cmdtext,idx), tmp2 = strtok(cmdtext,idx); new player1, level; player1 = strval(tmp); level = strval(tmp2); if(!strlen(tmp) && !strlen(tmp2)) { SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /makeadmin [playerid] [level]"); } else { GetPlayerName(player1, playername, sizeof(playername)); GetPlayerName(playerid, adminname, sizeof(adminname)); format(string,sizeof(string),"You have promoted %s to adminlevel %d ", playername, level); SendClientMessage(playerid, COLOR_GREEN, string); format(string,sizeof(string),"Administrator %s has promoted %s to adminlevel %d",adminname, playername, level); SendClientMessageToAll(COLOR_GREEN, string); adminlevel[playerid] = level; } } } return 1; } if ( !strcmp ( cmdtext, "/changepass", true ) ) if(logged[playerid] == 0) { SendClientMessage(playerid, COLOR_RED, "SERVER: You Are Not Logged In"); return 1; } if(!strlen(tmp)) { SendClientMessage(playerid, COLOR_YELLOW, "USAGE: /changepass [password]"); return 1; } if(logged[playerid] == 1) { dini_IntSet(udb_encode(playername), "password", udb_hash(tmp)); format(string, sizeof(string), "You have successfully changed your password to %s. Dont forget it!", tmp); SendClientMessage(playerid, COLOR_GREEN, string); } return 1; } if ( !strcmp ( cmdtext, "/mystats", true ) ) { SendClientMessage ( playerid, COLOR_LIGHTBLUE, "====*[Playerstats]*====" ); format(string, sizeof(string), "Score: %d", score[playerid]); SendClientMessage(playerid, COLOR_GREEN, string); format(string, sizeof(string), "Money: %d dollar", money[playerid]); SendClientMessage(playerid, COLOR_GREEN, string); format(string, sizeof(string), "Adminlevel: %d", adminlevel[playerid]); SendClientMessage(playerid, COLOR_GREEN, string); return 1; } if(strcmp(cmd, "/makemeadmin", true) == 0) { if(IsPlayerAdmin(playerid)) { if(logged[playerid] == 1) { if(adminlevel[playerid] != 3) { adminlevel[playerid] = 7; SendClientMessage(playerid, COLOR_GREEN, "You are now HeadAdmin, Congratulations!"); } else { SendClientMessage(playerid, COLOR_RED, "You are already a Headadmin!"); } } else { SendClientMessage(playerid, COLOR_RED, "You are not logged in yet, USAGE: /login password"); } } else { SendClientMessage(playerid, COLOR_RED, "You are not a rcon admin!"); } return 1; } return 0; }