Guest User

Server

a guest
Apr 14th, 2012
96
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 10.04 KB | None | 0 0
  1. // =============================================================================
  2. // =============================================================================
  3. // =============================================================================
  4. // =============================================================================
  5. // ----------------- Define Roleplay Romania Under Developing ------------------
  6. // =============================================================================
  7. // =============================================================================
  8. // =============================================================================
  9. // =============================================================================
  10.  
  11. // --------------------------- Bibliotecile necesare ---------------------------
  12.  
  13. #include <a_samp>
  14. #include <YSI\y_ini>
  15.  
  16. // =============================================================================
  17.  
  18. // --------------------------- Definitiile necesare ----------------------------
  19.  
  20. #define Dialog_Inregistrare 1
  21. #define Dialog_Logare 2
  22. #define Dialog_Conectare_1 3
  23. #define Dialog_Conectare_2 4
  24.  
  25. #define PATH "/Conturi/%s.ini"
  26.  
  27. // =============================================================================
  28.  
  29. // --------------------------- Variabilele necesare ----------------------------
  30.  
  31. // =============================================================================
  32.  
  33. // ---------------------- Variabile cu functie de returnare --------------------
  34.  
  35. forward LoadUser_data (playerid, name[], value[]);
  36.  
  37. // =============================================================================
  38.  
  39. // --------------------------- Enumeratiile necesare ---------------------------
  40.  
  41. enum pInfo
  42. {
  43. pParola,
  44. pBani,
  45. pAdmin,
  46. pCrime,
  47. pDecese
  48. }
  49. new PlayerInfo [MAX_PLAYERS] [pInfo];
  50.  
  51. // =============================================================================
  52.  
  53. // ------------------------ Functii cu valoarea initiala -----------------------
  54.  
  55. stock UserPath (playerid)
  56. {
  57. new Mesaj [256];
  58. new Nume [MAX_PLAYER_NAME];
  59. GetPlayerName (playerid, Nume, sizeof (Nume));
  60. format (Mesaj, sizeof (Mesaj), PATH, Nume);
  61. return Mesaj;
  62. }
  63.  
  64. stock udb_hash (buf[])
  65. {
  66. new Durata = strlen (buf);
  67. new s = 1;
  68. new d = 0;
  69. new n;
  70. for (n=0; n <= Durata; n++)
  71. {
  72. s = (s + buf [n]) % 65521;
  73. d = (d + s) % 65521;
  74. }
  75. return (d << 16) + s;
  76. }
  77.  
  78. strtok (const string[], &index)
  79. {
  80. new Durata = strlen (string);
  81. while ((index < Durata) && (string [index] <= ' '))
  82. {
  83. index++;
  84. }
  85.  
  86. new Variabila = index;
  87. new Rezultat [20];
  88. while ((index < Durata) && (string [index] > ' ') && ((index - Variabila) < (sizeof (Rezultat) - 1)))
  89. {
  90. Rezultat [index - Variabila] = string [index];
  91. index++;
  92. }
  93. Rezultat [index - Variabila] = EOS;
  94. return Rezultat;
  95. }
  96.  
  97. ReturnUser (string [])
  98. {
  99. new Este_Numeric = 1;
  100. new tmpstring [MAX_PLAYER_NAME];
  101. for (new Celula; Celula < strlen (string); Celula++)
  102. {
  103. if ((string [Celula] <= '0') || (string [Celula] >= '9'))
  104. {
  105. Este_Numeric = 0;
  106. }
  107. if (Este_Numeric)
  108. {
  109. return strval (string);
  110. }
  111. else
  112. {
  113. for (new Jucatori; Jucatori < MAX_PLAYERS; Jucatori++)
  114. {
  115. GetPlayerName (Jucatori, tmpstring, sizeof (tmpstring));
  116. if (strfind (tmpstring, string, true) > -1)
  117. {
  118. return Jucatori;
  119. }
  120. }
  121. }
  122. }
  123. return INVALID_PLAYER_ID;
  124. }
  125.  
  126. // =============================================================================
  127.  
  128. // ----------------------------- Functii generale ------------------------------
  129.  
  130. public LoadUser_data (playerid, name[], value[])
  131. {
  132. INI_Int ("Parola", PlayerInfo [playerid] [pParola]);
  133. INI_Int ("Bani", PlayerInfo [playerid] [pBani]);
  134. INI_Int ("Admin", PlayerInfo [playerid] [pAdmin]);
  135. INI_Int ("Crime", PlayerInfo [playerid] [pCrime]);
  136. INI_Int ("Decese", PlayerInfo [playerid] [pDecese]);
  137. return 1;
  138. }
  139.  
  140. public OnPlayerConnect (playerid)
  141. {
  142. if (fexist (UserPath (playerid)))
  143. {
  144. INI_ParseFile (UserPath (playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  145. ShowPlayerDialog (playerid, Dialog_Logare, DIALOG_STYLE_INPUT, "{336633}Fereastra de logare", "{FFCC99}Bine ai revenit pe {6666CC}Define Roleplay Romania{FFCC99}. \n{FFCC99}Acest cont {66FF33}este inregistrat {FFCC99}in baza noastra de date. \n{FFCC99}Te rog introdu parola corecta in casuta de mai jos pentru a te conecta.", "Ok", "Renunta");
  146. }
  147. else
  148. {
  149. ShowPlayerDialog (playerid, Dialog_Inregistrare, DIALOG_STYLE_INPUT, "{336633}Fereastra de inregistrare", "{FFCC99}Bine ai venit pe {6666CC}Define Roleplay Romania{FFCC99}. \n{FFCC99}Acest cont {CC0000}nu este inregistrat {FFCC99}in baza noastra de date. \n{FFCC99}Te rog introdu parola dorita in casuta de mai jos pentru a te inregistra.", "Ok", "Renunta");
  150. }
  151. return 1;
  152. }
  153.  
  154. public OnDialogResponse (playerid, dialogid, response, listitem, inputtext[])
  155. {
  156. switch (dialogid)
  157. {
  158. case Dialog_Inregistrare :
  159. {
  160. if (!response)
  161. {
  162. return Kick (playerid);
  163. }
  164. if (response)
  165. {
  166. if (!strlen (inputtext))
  167. {
  168. return ShowPlayerDialog (playerid, Dialog_Inregistrare, DIALOG_STYLE_INPUT, "{336633}Fereastra de inregistrare", "{FFCC99}Nu ai reusit sa te conectezi la server deoarece parola introdusa este {CC0000}incorecta{FFCC99}. \n{FFCC99}Te rog introdu o parola in casuta de mai jos pentru a te conecta.", "Ok", "Renunta");
  169. }
  170. new INI:Fisier = INI_Open (UserPath (playerid));
  171. INI_SetTag (Fisier, "data");
  172. INI_WriteInt (Fisier, "Parola", udb_hash (inputtext));
  173. INI_WriteInt (Fisier, "Bani", 0);
  174. INI_WriteInt (Fisier, "Admin", 0);
  175. INI_WriteInt (Fisier, "Crime", 0);
  176. INI_WriteInt (Fisier, "Decese", 0);
  177. INI_Close (Fisier);
  178.  
  179. SetSpawnInfo (playerid, 0, 0, 1642.2238, -2332.9924, 13.5469, 359.0938, 0, 0, 0, 0, 0 , 0);
  180. SpawnPlayer (playerid);
  181. PlayerInfo [playerid] [pBani] = 600;
  182. GivePlayerMoney (playerid, PlayerInfo [playerid] [pBani]);
  183. ShowPlayerDialog (playerid, Dialog_Conectare_1, DIALOG_STYLE_MSGBOX, "{66CC00}Fereastra de conectare", "{FFCC99}Te-ai conectat cu {66CC00}succes {FFCC99}pe Define Roleplay Romania. \n{FFCC99}Echipa noastra iti ureaza o distractie placuta.", "Ok", "");
  184. }
  185. }
  186. case Dialog_Logare :
  187. {
  188. if (!response)
  189. {
  190. return Kick (playerid);
  191. }
  192. if (response)
  193. {
  194. if (udb_hash (inputtext) == PlayerInfo [playerid] [pParola])
  195. {
  196. INI_ParseFile (UserPath (playerid), "LoadUser_%s", .bExtra = true, .extra = playerid);
  197. GivePlayerMoney (playerid, PlayerInfo [playerid] [pBani]);
  198. SetSpawnInfo (playerid, 0, 0, 1642.2238, -2332.9924, 13.5469, 359.0938, 0, 0, 0, 0, 0 , 0);
  199. SpawnPlayer (playerid);
  200. ShowPlayerDialog (playerid, Dialog_Conectare_2, DIALOG_STYLE_MSGBOX, "{66CC00}Fereastra de conectare", "{FFCC99}Te-ai conectat cu {66CC00}succes {FFCC99}pe Define Roleplay Romania. \n{FFCC99}Echipa noastra iti ureaza o distractie placuta.", "Ok", "");
  201. }
  202. else
  203. {
  204. ShowPlayerDialog (playerid, Dialog_Logare, DIALOG_STYLE_INPUT, "{336633}Fereastra de logare", "{FFCC99}Nu ai reusit sa te conectezi la server deoarece parola introdusa este {CC0000}incorecta{FFCC99}. \n{FFCC99}Te rog introdu parola corecta in casuta de mai jos pentru a te conecta.", "Ok", "Renunta");
  205. }
  206. return 1;
  207. }
  208. }
  209. }
  210. return 1;
  211. }
  212.  
  213. public OnPlayerCommandText (playerid, cmdtext[])
  214. {
  215. new Comanda [256];
  216. new Variabila;
  217.  
  218. if (strcmp (Comanda, "/asetadmin", true) == 0)
  219. {
  220. new Mesaj [256];
  221. new Format [256];
  222. new Trimitator [MAX_PLAYER_NAME];
  223. new Receptor [MAX_PLAYER_NAME];
  224. new Receptor_ID;
  225. if (PlayerInfo [playerid] [pAdmin] == 4)
  226. {
  227. Format = strtok (cmdtext, Variabila);
  228. if (!strlen (Format))
  229. {
  230. SendClientMessage (playerid, 0xFFFFFF, "{CC0000}*** {336633}[Informatie] {FFCC99}Formatul corect al acestei comenzi este : '/asetadmin [ID Jucator] [Nivel Admin]'. {CC0000}***");
  231. return 1;
  232. }
  233. Receptor_ID = ReturnUser (Format);
  234. Format = strtok (cmdtext, Variabila);
  235. new Nivel = strval (Format);
  236. if (Receptor_ID != INVALID_PLAYER_ID)
  237. {
  238. GetPlayerName (Receptor_ID, Receptor, sizeof (Receptor));
  239. GetPlayerName (playerid, Trimitator, sizeof (Trimitator));
  240. PlayerInfo [Receptor_ID] [pAdmin] = Nivel;
  241. format (Mesaj, sizeof (Mesaj), "{CC0000}*** {336633}[Informatie] {FFCC99}Ai fost promovat la statutul de Admin Level %d de Administratorul %s. Felicitari. {CC0000}***", Nivel, Trimitator);
  242. SendClientMessage (Receptor_ID, 0xFFFFFF, Mesaj);
  243. format (Mesaj, sizeof (Mesaj), "{CC0000}*** {336633}[Informatie] {FFCC99}L-ai promovat la statutul de Admin Level %s pe %d. Speram sa nu dezamageasca. {CC0000}***", Receptor, PlayerInfo [Receptor_ID] [pAdmin]);
  244. SendClientMessage (playerid, 0xFFFFFF, Mesaj);
  245. }
  246. else if (Receptor_ID == INVALID_PLAYER_ID)
  247. {
  248. format (Mesaj, sizeof (Mesaj), "{CC0000}*** {336633}[Informatie] {FFCC99}%i nu este conectat pe server. Verifica daca ai scris ID-ul corect. {CC0000}***", Receptor_ID);
  249. SendClientMessage (playerid, 0xFFFFFF, Mesaj);
  250. }
  251.  
  252. }
  253. else
  254. {
  255. SendClientMessage (playerid, 0xFFFFFF, "{CC0000}*** {336633}[Informatie] {FFCC99}Nu esti autorizat sa folosesti aceasta comanda. Ia legatura cu unul din membrii echipei noastre pentru mai multe detalii. {CC0000}***");
  256. }
  257. return 1;
  258. }
  259. return 0;
  260. }
  261.  
  262. public OnPlayerDisconnect (playerid, reason)
  263. {
  264. new INI:Fisier = INI_Open (UserPath (playerid));
  265. INI_SetTag (Fisier, "data");
  266. INI_WriteInt (Fisier, "Bani", GetPlayerMoney (playerid));
  267. INI_WriteInt (Fisier, "Admin", PlayerInfo [playerid] [pAdmin]);
  268. INI_WriteInt (Fisier, "Crime", PlayerInfo [playerid] [pCrime]);
  269. INI_WriteInt (Fisier, "Decese", PlayerInfo [playerid] [pDecese]);
  270. INI_Close (Fisier);
  271. return 1;
  272. }
  273.  
  274. public OnPlayerDeath (playerid, killerid, reason)
  275. {
  276. PlayerInfo [killerid] [pCrime] ++;
  277. PlayerInfo [playerid] [pDecese] --;
  278. return 1;
  279. }
Advertisement
Add Comment
Please, Sign In to add comment