Advertisement
Guest User

TimeBan Mysql Zabus

a guest
Sep 9th, 2010
792
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 4.13 KB | None | 0 0
  1. #include <a_samp>
  2. #include <mysql>
  3. #include <ocmd>
  4. #include <sscanf2>
  5.  
  6. forward timebancheck(playerid); // ganz nach oben !!
  7. new gPlayerName[MAX_PLAYERS][MAX_PLAYER_NAME],gPlayerIP[MAX_PLAYERS][16];
  8.  
  9. public OnPlayerConnect(playerid)
  10. {
  11.     GetPlayerName(playerid, gPlayerName[playerid], MAX_PLAYER_NAME);
  12.     GetPlayerIp(playerid,gPlayerIP[playerid],16);
  13.     timebancheck(playerid);
  14.     return 1;
  15. }
  16.  
  17. //TIMEBANBEFEHL einfach ober OnPLayerCommandText ;)
  18. ocmd:timeban(playerid,params[])
  19. {
  20.     new pid,
  21.     grund[128],dauer;
  22.     if(sscanf(params,"uds[128]",pid,dauer,grund)) return SendClientMessage(playerid,COLOR_YELLOW,"Benutzung:/timeban [ID][Dauer][GRUND]");
  23.     if(Spieler[playerid][pAdmin] < 1) return SendClientMessage(playerid,COLOR_RED,"Du bist kein Admin");
  24.     if(!IsPlayerConnected(pid)) return SendClientMessage(playerid,COLOR_RED,"Kein Spieler mit der angegebenen ID ist Online");
  25.     new string[128],
  26.     string2[128];
  27.     format(string,sizeof(string),"Du wurdest für %d Minuten vom Server gebannt Grund:%s",dauer,grund);
  28.     format(string2,sizeof(string),"Du hast %s für %d Minuten vom Server gebannt",gPlayerName[pid],dauer);
  29.     SendClientMessage(pid,COLOR_RED,string);
  30.     SendClientMessage(playerid,COLOR_RED,string2);
  31.     Kick(pid);
  32.     new zeitdauer=Now()+dauer*60;
  33.     timebanplayer(gPlayerName[pid],grund,gPlayerIP[pid],gPlayerName[playerid],zeitdauer);
  34.     return 1;
  35. }
  36.  
  37. ocmd:unban(playerid,params[])
  38. {
  39.     new unbanname[MAX_PLAYER_NAME];
  40.     if(sscanf(params,"s[24]",unbanname)) return SendClientMessage(playerid,COLOR_YELLOW,"Benutzung. /unban [NAME]");
  41.     if(Spieler[playerid][pAdmin] < 1) return SendClientMessage(playerid,COLOR_RED,"Du bist kein Admin");
  42.     format(query,sizeof(query),"DELETE FROM `timeban `Name`='%s'",unbanname);
  43.     mysql_query(query);
  44.     return 1;
  45. }
  46.  
  47. public OnPlayerCommandText(playerid, cmdtext[])
  48. {
  49.     if (strcmp("/mycommand", cmdtext, true, 10) == 0)
  50.     {
  51.         // Do something here
  52.         return 1;
  53.     }
  54.     return 0;
  55. }
  56. // Das einfach ganz unten hinzufügen
  57. public timebancheck(playerid)
  58. {
  59.     new query[256],
  60.     data[255],ergebnis,timestamp;
  61.     format(query,sizeof(query),"SELECT * FROM `timeban` WHERE `IP`='%s' OR `Name`='%s'",gPlayerIP[playerid],gPlayerName[playerid]);
  62.     mysql_query(query);
  63.     mysql_store_result();
  64.     if(mysql_num_rows())
  65.     {
  66.         mysql_fetch_field("ID",data);
  67.         ergebnis=strval(data);
  68.         mysql_fetch_field("Datum",data);
  69.         timestamp=strval(data);
  70.         if(ergebnis!=0)
  71.         {
  72.         if(Now()<timestamp)
  73.         {
  74.         new string[128];
  75.         new zahl=timestamp-Now();
  76.         zahl=zahl/60;
  77.         format(string,128,"Du bist noch %d Minuten gebannt",zahl);
  78.         SendClientMessage(playerid,COLOR_RED,string);
  79.         return Kick(playerid);
  80.         }
  81.         else
  82.         {
  83.         format(query,sizeof(query),"DELETE FROM `timeban` WHERE `IP`='%s' OR `Name`='%s'",gPlayerIP[playerid],gPlayerName[playerid]);
  84.         mysql_query(query);
  85.         }
  86.         }
  87.     }
  88.     mysql_free_result();
  89.     return 1;
  90. }
  91.  
  92. //hier auch ganz nach unten die stocks
  93. stock mktime(hour,minute,second,day,month,year)
  94. {
  95.     new timestamp2;
  96.  
  97.     timestamp2 = second + (minute * 60) + (hour * 3600);
  98.  
  99.     new days_of_month[12];
  100.  
  101.     if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) {
  102.             days_of_month = {31,29,31,30,31,30,31,31,30,31,30,31}; // Schaltjahr
  103.         } else {
  104.             days_of_month = {31,28,31,30,31,30,31,31,30,31,30,31}; // keins
  105.         }
  106.     new days_this_year = 0;
  107.     days_this_year = day;
  108.     if(month > 1) { // No January Calculation, because its always the 0 past months
  109.         for(new i=0; i<month-1;i++) {
  110.             days_this_year += days_of_month[i];
  111.         }
  112.     }
  113.     timestamp2 += days_this_year * 86400;
  114.  
  115.     for(new j=1970;j<year;j++) {
  116.         timestamp2 += 31536000;
  117.         if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) )  timestamp2 += 86400; // Schaltjahr + 1 Tag
  118.     }
  119.  
  120.     return timestamp2;
  121. }
  122.  
  123. stock Now()
  124. {
  125.     new hour,minute,second,year,month,day;
  126.     gettime(hour, minute, second);
  127.     getdate(year, month, day);
  128.     return mktime(hour,minute,second,day,month,year);
  129. }
  130.  
  131. stock timebanplayer(nickname[24],grund[128],playerIP[16],admin[24],dauer)
  132. {
  133.     new query[256];
  134.     format(query,sizeof(query),"INSERT INTO timeban (Name,Grund,IP,Admin,Datum) VALUES ('%s','%s','%s','%s','%d')",
  135.     nickname,
  136.     grund,
  137.     playerIP,
  138.     admin,
  139.     dauer);
  140.     mysql_query(query);
  141.     mysql_free_result();
  142. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement