Advertisement
Guest User

Mysql E-Mail system v1.0

a guest
Jul 30th, 2011
3,551
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 17.30 KB | None | 0 0
  1. /*********************\
  2.  Mysql E-mail system
  3.  Made by wups
  4.  Version 1.0
  5. \*********************/
  6.  
  7. #include <a_samp>
  8. #include <a_mysql>
  9.  
  10.  
  11. // You must configure these!
  12. #define SQL_IP                        ""
  13. #define SQL_USER                      ""
  14. #define SQL_PASSWORD                  ""
  15. #define SQL_DB                        ""
  16. // End
  17.  
  18.  
  19. // defines (ignore them)
  20. #define QUERY(%0)  mysql_query(%0, -1, -1, mysql_connection)
  21.  
  22. #define CREATE_QUERY    "CREATE TABLE IF NOT EXISTS `Emails`( \
  23.                         `Sender` varchar(100) NOT NULL,`Reciever` varchar(100) NOT NULL, \
  24.                         `Date` varchar(24) NOT NULL,`Time` varchar(24) NOT NULL,`MK` int(11) NOT NULL, \
  25.                         `New` smallint(6) NOT NULL,`Subject` varchar(100) NOT NULL,`Text` mediumtext NOT NULL) \
  26.                         ENGINE=MyISAM DEFAULT CHARSET=latin1 \
  27.                         COLLATE=latin1_general_cs AUTO_INCREMENT=1"
  28. #define DIALOGID 7654
  29.  
  30. #define FREE mysql_free_result(mysql_connection)
  31. #define STORE mysql_store_result(mysql_connection)
  32. #define ROWS mysql_num_rows(mysql_connection)
  33.                        
  34. // variables
  35.  
  36. static  mysql_connection;
  37. new     SubjectP[MAX_PLAYERS][100],
  38.         RecieverP[MAX_PLAYERS][50],
  39.         MkP[MAX_PLAYERS];
  40. // functions
  41. public OnFilterScriptInit()
  42. {
  43.     mysql_debug(1);
  44.    mysql_connection = mysql_connect(SQL_IP, SQL_USER, SQL_DB, SQL_PASSWORD);
  45.     QUERY(CREATE_QUERY);
  46.     print("\n--------------------------------------");
  47.     print(" Mysql E-Mail system by wups Loaded!");
  48.     print("--------------------------------------\n");
  49.     return 1;
  50. }
  51.  
  52. public OnFilterScriptExit()
  53. {
  54.     mysql_close(mysql_connection);
  55.     print("\n--------------------------------------");
  56.     print(" Mysql E-Mail system by wups Unloaded!");
  57.     print("--------------------------------------\n");
  58.  
  59.     return 1;
  60. }
  61.  
  62. public OnPlayerConnect(playerid)
  63. {
  64.     return 1;
  65. }
  66.  
  67. public OnPlayerDisconnect(playerid, reason)
  68. {
  69.     return 1;
  70. }
  71.  
  72. public OnPlayerSpawn(playerid)
  73. {
  74.     return 1;
  75. }
  76.  
  77. public OnPlayerDeath(playerid, killerid, reason)
  78. {
  79.     return 1;
  80. }
  81.  
  82.  
  83. public OnPlayerText(playerid, text[])
  84. {
  85.     return 1;
  86. }
  87.  
  88. public OnPlayerCommandText(playerid, cmdtext[])
  89. {
  90.     if(!strcmp("/email", cmdtext, true))
  91.     {
  92.         ShowEmail(playerid);
  93.         return 1;
  94.     }
  95.     return 0;
  96. }
  97. stock ShowEmail(playerid)
  98. {
  99.         new string[128],
  100.             name[MAX_PLAYER_NAME],
  101.             inbox,
  102.             outbox;
  103.  
  104.         GetPlayerName(playerid,name,MAX_PLAYER_NAME);
  105.  
  106.         format(string,sizeof(string),"SELECT `New` FROM `Emails` WHERE `Reciever`='%s' AND `New`=1",name);
  107.         QUERY(string);
  108.         STORE;
  109.         inbox = ROWS;
  110.         FREE;
  111.  
  112.         format(string,sizeof(string),"SELECT `New` FROM `Emails` WHERE `Sender`='%s' AND `New`=1",name);
  113.         QUERY(string);
  114.         STORE;
  115.         outbox = ROWS;
  116.         FREE;
  117.  
  118.         format(string,sizeof(string),"{FFFFFF}\
  119.                                         Inbox({FF0000}%i{FFFFFF} New)\n\
  120.                                         Outbox({FF0000}%i{FFFFFF} Unread)\n\
  121.                                         Compose",inbox,outbox);
  122.         ShowPlayerDialog(playerid, DIALOGID, DIALOG_STYLE_LIST,"E-Mail",string,"Ok","Cancel");
  123.         return 1;
  124. }
  125.  
  126. public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
  127. {
  128.     mysql_real_escape_string(inputtext,inputtext);
  129.     switch(dialogid)
  130.     {
  131.         case DIALOGID-1: // reply/delete
  132.         {
  133.             if(response)
  134.             {
  135.                 ShowPlayerDialog(playerid,DIALOGID+31,DIALOG_STYLE_INPUT,"Compose","Input the Subject.\nMax Lenght: 100 symbols.","Ok","Back");
  136.                 return 1;
  137.             }
  138.             else
  139.             {
  140.                 new query[128];
  141.                 format(query,sizeof(query),"DELETE FROM `Emails` WHERE MK=%i LIMIT 1",MkP[playerid]);
  142.                 QUERY(query);
  143.                 SendClientMessage(playerid,0xFFFFFF30," * Message deleted!");
  144.                 ShowEmail(playerid);
  145.                 return 1;
  146.             }
  147.         }
  148.         case DIALOGID-2:
  149.         {
  150.             ShowEmail(playerid);
  151.             return 1;
  152.         }
  153.         case DIALOGID+1: // inbox
  154.         {
  155.             if(response)
  156.             {
  157.                 new result[1024],
  158.                     name[MAX_PLAYER_NAME],
  159.                     Subject[100],
  160.                     Sender[60],
  161.                     Time[15],
  162.                     Date[20],
  163.                     Message[256],
  164.                     New=0,
  165.                     Mk;
  166.  
  167.                 GetPlayerName(playerid,name,MAX_PLAYER_NAME);
  168.                 format(result,sizeof(result),"SELECT `Sender`,`Subject`,`Time`,`Date`,`New`,`MK`,`Text` FROM `Emails` WHERE `Reciever`='%s' ORDER BY `MK` DESC LIMIT %i,1",name,listitem);
  169.                 QUERY(result);
  170.                 STORE;
  171.                 mysql_fetch_row_format(result,"|",mysql_connection);
  172.                 sscanf(result,"ssssiis",Sender,Subject,Time,Date,New,Mk,Message);
  173.                 replaceChar(Message,'~','\n');
  174.                 format(result,sizeof(result),"{FFFFFF}Date:{FF9933} %s{FFFF33} %s\n{FFFFFF}Sender:{FFFF33} %s\n{FFFFFF}Subject: %s\n\n\n%s",Date,Time,Sender,Subject,Message);
  175.                 FREE;
  176.                
  177.                 format(RecieverP[playerid],60,"%s",Sender);
  178.                 MkP[playerid]=Mk;
  179.                 ShowPlayerDialog(playerid,DIALOGID-1,DIALOG_STYLE_MSGBOX,"Message",result,"Reply","Delete");
  180.                 if(New)
  181.                 {
  182.                     format(result,sizeof(result),"UPDATE `Emails` SET `New`=0 WHERE `MK`='%i' LIMIT 1",Mk);
  183.                     QUERY(result);
  184.                 }
  185.             }
  186.             else ShowEmail(playerid);
  187.             return 1;
  188.         }
  189.         case DIALOGID+2: // outbox
  190.         {
  191.             if(response)
  192.             {
  193.                 new result[1024],
  194.                     name[MAX_PLAYER_NAME],
  195.                     Subject[100],
  196.                     Reciever[60],
  197.                     Time[15],
  198.                     Date[20],
  199.                     Message[256];
  200.  
  201.                 GetPlayerName(playerid,name,MAX_PLAYER_NAME);
  202.                 format(result,sizeof(result),"SELECT `Reciever`,`Subject`,`Time`,`Date`,`Text` FROM `Emails` WHERE `Sender`='%s' ORDER BY `MK` DESC LIMIT %i,1",name,listitem);
  203.                 QUERY(result);
  204.                 STORE;
  205.                 mysql_fetch_row_format(result,"|",mysql_connection);
  206.                 sscanf(result,"sssss",Reciever,Subject,Time,Date,Message);
  207.                 format(result,sizeof(result),"{FFFFFF}Date:{FF9933} %s{FFFF33} %s\n{FFFFFF}Reciever:{FFFF33} %s\n{FFFFFF}Subject: %s\n\n\n%s",Date,Time,Reciever,Subject,Message);
  208.                 FREE;
  209.                 ShowPlayerDialog(playerid,DIALOGID-2,DIALOG_STYLE_MSGBOX,"Message",result,"Ok","Cancel");
  210.             }
  211.             else ShowEmail(playerid);
  212.             return 1;
  213.         }
  214.         case DIALOGID: // main dialog
  215.         {
  216.             if(response)
  217.             {
  218.                 switch(listitem)
  219.                 {
  220.                     case 0: // inbox
  221.                     {
  222.                         new result[3048],
  223.                             name[MAX_PLAYER_NAME],
  224.                             QR[256],
  225.                             Subject[100],
  226.                             Sender[60],
  227.                             Time[10],
  228.                             New
  229.                             ;
  230.                         GetPlayerName(playerid,name,MAX_PLAYER_NAME);
  231.                         format(QR,sizeof(QR),"SELECT `Sender`,`Subject`,`Time`,`New` FROM `Emails` WHERE `Reciever`='%s' ORDER BY `MK` DESC LIMIT 20",name);
  232.                         QUERY(QR);
  233.                         STORE;
  234.                         if(!ROWS) return SendClientMessage(playerid,0xFFFFFF30," * You don't have any messages in your inbox!");
  235.                         while(mysql_fetch_row_format(QR,"|",mysql_connection))
  236.                         {
  237.                             sscanf(QR,"sssi",Sender,Subject,Time,New);
  238.                             if(!New)
  239.                                 format(result,sizeof(result),"%s{FFFFFF}'%s'{FF9933} FROM %s{FFFF33} %s\n",result,Subject,Sender,Time);
  240.                             else
  241.                                 format(result,sizeof(result),"%s{FFFFFF}'%s'{FF9933} FROM %s{FFFF33} NEW\n",result,Subject,Sender);
  242.  
  243.                         }
  244.                         FREE;
  245.                         ShowPlayerDialog(playerid,DIALOGID+1,DIALOG_STYLE_LIST,"Inbox",result,"Ok","Back");
  246.                         return 1;
  247.                     }
  248.                    case 1: // outbox
  249.                     {
  250.                         new result[3048],
  251.                             name[MAX_PLAYER_NAME],
  252.                             QR[256],
  253.                             Subject[100],
  254.                             Reciever[60],
  255.                             Time[10],
  256.                             New
  257.                             ;
  258.                         GetPlayerName(playerid,name,MAX_PLAYER_NAME);
  259.                         format(QR,sizeof(QR),"SELECT `Reciever`,`Subject`,`Time`,`New` FROM `Emails` WHERE `Sender`='%s' ORDER BY `MK` DESC LIMIT 20",name);
  260.                         QUERY(QR);
  261.                         STORE;
  262.                         if(!ROWS) return SendClientMessage(playerid,0xFFFFFF30," * You don't have any messages in your outbox!");
  263.                         while(mysql_fetch_row_format(QR,"|",mysql_connection))
  264.                         {
  265.                             sscanf(QR,"sssi",Reciever,Subject,Time,New);
  266.                             if(!New)
  267.                                 format(result,sizeof(result),"%s{FFFFFF}'%s'{FF9933} TO %s{FFFF33} %s\n",result,Subject,Reciever,Time);
  268.                             else
  269.                                 format(result,sizeof(result),"%s{FFFFFF}'%s'{FF9933} TO %s{FFFF33} UNREAD\n",result,Subject,Reciever);
  270.                         }
  271.                         FREE;
  272.                         ShowPlayerDialog(playerid,DIALOGID+2,DIALOG_STYLE_LIST,"Outbox",result,"Ok","Back");
  273.                         return 1;
  274.                     }
  275.                     case 2: // compose
  276.                     {
  277.                         ShowPlayerDialog(playerid,DIALOGID+30,DIALOG_STYLE_INPUT,"Compose","Input the Recipients E-Mail address.\nFormat - Name","Ok","Back");
  278.                         return 1;
  279.                     }
  280.                 }
  281.             }
  282.         }
  283.         case DIALOGID+30: // compose 1
  284.         {
  285.             if(response)
  286.             {
  287.                 if(strlen(inputtext) > 50 || strlen(inputtext) < 5 || strfind(inputtext,"\n",true) != -1 || strfind(inputtext,"{",true) != -1 || strfind(inputtext,"}",true) != -1 || strfind(inputtext,"|",true) != -1 ) return ShowPlayerDialog(playerid,DIALOGID+30,DIALOG_STYLE_INPUT,"Compose","Input the Recipients E-Mail address.\nFormat - Name\nE-Mail address Name is in wrong format!","Ok","Back");
  288.                 format(RecieverP[playerid],50,inputtext);
  289.                 ShowPlayerDialog(playerid,DIALOGID+31,DIALOG_STYLE_INPUT,"Compose","Input the Subject.\nMax Lenght: 100 symbols.","Ok","Back");
  290.                 return 1;
  291.             }
  292.             else
  293.             {
  294.                ShowEmail(playerid);
  295.                return 1;
  296.             }
  297.         }
  298.         case DIALOGID+31: // compose 2
  299.         {
  300.            
  301.             if(response)
  302.             {
  303.                 if(strlen(inputtext) > 98 || strlen(inputtext) < 2 || strfind(inputtext,"\n",true) != -1 || strfind(inputtext,"{",true) != -1 || strfind(inputtext,"}",true) != -1 || strfind(inputtext,"|",true) != -1) return ShowPlayerDialog(playerid,DIALOGID+30,DIALOG_STYLE_INPUT,"Compose","Input the Subject.\nMax Lenght: 100 symbols.\nSubject is invalid format!","Ok","Back");
  304.                 format(SubjectP[playerid],100,inputtext);
  305.                 ShowPlayerDialog(playerid,DIALOGID+32,DIALOG_STYLE_INPUT,"Compose","Write the message.\nMax Lenght: 256 symbols.\n '~' Indicates a new line.","Ok","Back");
  306.                 return 1;
  307.             }
  308.             else
  309.             {
  310.                ShowEmail(playerid);
  311.                return 1;
  312.             }
  313.         }
  314.         case DIALOGID+32: // compose 3
  315.         {
  316.             if(response)
  317.             {
  318.                 if(strlen(inputtext) > 255 || strlen(inputtext) < 2) return ShowPlayerDialog(playerid,DIALOGID+32,DIALOG_STYLE_INPUT,"Compose","Write the message.\nMax Lenght: 256 symbols.\nMessage too short or too long!","Ok","Back");
  319.                 if(strfind(inputtext,"\n",true) != -1 || strfind(inputtext,"{",true) != -1 || strfind(inputtext,"}",true) != -1 || strfind(inputtext,"|",true) != -1) return ShowPlayerDialog(playerid,DIALOGID+32,DIALOG_STYLE_INPUT,"Compose","Write the message.\nMax Lenght: 256 symbols.\nMessage contains blocked symbols!","Ok","Back");
  320.                 new
  321.                     query[1024],
  322.                     hour,
  323.                     minute,
  324.                     second,
  325.                     day,
  326.                     month,
  327.                     year,
  328.                     mk,
  329.                     name[MAX_PLAYER_NAME];
  330.                    
  331.                 gettime(hour,minute,second);
  332.                 getdate(year,month,day);
  333.                 mk = mktime(hour,minute,second,day,month,year);
  334.                 GetPlayerName(playerid,name,MAX_PLAYER_NAME);
  335.                 format(query,sizeof(query),"INSERT INTO `Emails` (Sender,Reciever,Date,Time,MK,New,Subject,Text) VALUES('%s','%s','%i-%i-%i','%i:%i',%i,1,'%s','%s')",
  336.                                                                 name,RecieverP[playerid],day,month,year,hour,minute,mk,SubjectP[playerid],inputtext);
  337.                 QUERY(query);
  338.                 SendClientMessage(playerid,0xFFFFFF30," * Message sent!");
  339.                 return 1;
  340.             }
  341.             else
  342.             {
  343.                ShowEmail(playerid);
  344.                return 1;
  345.             }
  346.         }
  347.    }
  348.     return 0;
  349. }
  350.  
  351. // Libraries
  352. stock sscanf(string[], format[], {Float,_}:...) // credits Y_Less
  353. {
  354.     #if defined isnull
  355.         if (isnull(string))
  356.     #else
  357.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  358.     #endif
  359.         {
  360.             return format[0];
  361.         }
  362.     #pragma tabsize 4
  363.     new
  364.         formatPos = 0,
  365.         stringPos = 0,
  366.         paramPos = 2,
  367.         paramCount = numargs(),
  368.         delim = '|';
  369.     while (string[stringPos] && string[stringPos] <= ' ')
  370.     {
  371.         stringPos++;
  372.     }
  373.     while (paramPos < paramCount && string[stringPos])
  374.     {
  375.         switch (format[formatPos++])
  376.         {
  377.             case '\0':
  378.             {
  379.                 return 0;
  380.             }
  381.             case 'i':
  382.             {
  383.                 new
  384.                     neg = 1,
  385.                     num = 0,
  386.                     ch = string[stringPos];
  387.                 if (ch == '-')
  388.                 {
  389.                     neg = -1;
  390.                     ch = string[++stringPos];
  391.                 }
  392.                 do
  393.                 {
  394.                     stringPos++;
  395.                     if ('0' <= ch <= '9')
  396.                     {
  397.                         num = (num * 10) + (ch - '0');
  398.                     }
  399.                     else
  400.                     {
  401.                         return -1;
  402.                     }
  403.                 }
  404.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  405.                 setarg(paramPos, 0, num * neg);
  406.             }
  407.             case 'd':
  408.             {
  409.                 new
  410.                     num = 0,
  411.                     ch = string[stringPos];
  412.                 if (ch == '-')
  413.                 {
  414.                     return -1;
  415.                 }
  416.                 do
  417.                 {
  418.                     stringPos++;
  419.                     if ('0' <= ch <= '9')
  420.                     {
  421.                         num = (num * 10) + (ch - '0');
  422.                     }
  423.                     else
  424.                     {
  425.                         return -1;
  426.                     }
  427.                 }
  428.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  429.                 setarg(paramPos, 0, num);
  430.             }
  431.             case 'h', 'x':
  432.             {
  433.                 new
  434.                     num = 0,
  435.                     ch = string[stringPos];
  436.                 do
  437.                 {
  438.                     stringPos++;
  439.                     switch (ch)
  440.                     {
  441.                         case 'x', 'X':
  442.                         {
  443.                             num = 0;
  444.                             continue;
  445.                         }
  446.                         case '0' .. '9':
  447.                         {
  448.                             num = (num << 4) | (ch - '0');
  449.                         }
  450.                         case 'a' .. 'f':
  451.                         {
  452.                             num = (num << 4) | (ch - ('a' - 10));
  453.                         }
  454.                         case 'A' .. 'F':
  455.                         {
  456.                             num = (num << 4) | (ch - ('A' - 10));
  457.                         }
  458.                         default:
  459.                         {
  460.                             return -1;
  461.                         }
  462.                     }
  463.                 }
  464.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  465.                 setarg(paramPos, 0, num);
  466.             }
  467.             case 'c':
  468.             {
  469.                 setarg(paramPos, 0, string[stringPos++]);
  470.             }
  471.             case 'f':
  472.             {
  473.  
  474.                 new changestr[16], changepos = 0, strpos = stringPos;
  475.                 while(changepos < 16 && string[strpos] && string[strpos] != delim)
  476.                 {
  477.                     changestr[changepos++] = string[strpos++];
  478.                     }
  479.                 changestr[changepos] = '\0';
  480.                 setarg(paramPos,0,_:floatstr(changestr));
  481.             }
  482.             case 'p':
  483.             {
  484.                 delim = format[formatPos++];
  485.                 continue;
  486.             }
  487.             case '\'':
  488.             {
  489.                 new
  490.                     end = formatPos - 1,
  491.                     ch;
  492.                 while ((ch = format[++end]) && ch != '\'') {}
  493.                 if (!ch)
  494.                 {
  495.                     return -1;
  496.                 }
  497.                 format[end] = '\0';
  498.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  499.                 {
  500.                     if (format[end + 1])
  501.                     {
  502.                         return -1;
  503.                     }
  504.                     return 0;
  505.                 }
  506.                 format[end] = '\'';
  507.                 stringPos = ch + (end - formatPos);
  508.                 formatPos = end + 1;
  509.             }
  510.             case 'u':
  511.             {
  512.                 new
  513.                     end = stringPos - 1,
  514.                     id = 0,
  515.                     bool:num = true,
  516.                     ch;
  517.                 while ((ch = string[++end]) && ch != delim)
  518.                 {
  519.                     if (num)
  520.                     {
  521.                         if ('0' <= ch <= '9')
  522.                         {
  523.                             id = (id * 10) + (ch - '0');
  524.                         }
  525.                         else
  526.                         {
  527.                             num = false;
  528.                         }
  529.                     }
  530.                 }
  531.                 if (num && IsPlayerConnected(id))
  532.                 {
  533.                     setarg(paramPos, 0, id);
  534.                 }
  535.                 else
  536.                 {
  537.                     #if !defined foreach
  538.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  539.                         #define __SSCANF_FOREACH__
  540.                     #endif
  541.                     string[end] = '\0';
  542.                     num = false;
  543.                     new
  544.                         name[MAX_PLAYER_NAME];
  545.                     id = end - stringPos;
  546.                     foreach (Player, playerid)
  547.                     {
  548.                         GetPlayerName(playerid, name, sizeof (name));
  549.                         if (!strcmp(name, string[stringPos], true, id))
  550.                         {
  551.                             setarg(paramPos, 0, playerid);
  552.                             num = true;
  553.                             break;
  554.                         }
  555.                     }
  556.                     if (!num)
  557.                     {
  558.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  559.                     }
  560.                     string[end] = ch;
  561.                     #if defined __SSCANF_FOREACH__
  562.                         #undef foreach
  563.                         #undef __SSCANF_FOREACH__
  564.                     #endif
  565.                 }
  566.                 stringPos = end;
  567.             }
  568.             case 's', 'z':
  569.             {
  570.                 new
  571.                     i = 0,
  572.                     ch;
  573.                 if (format[formatPos])
  574.                 {
  575.                     while ((ch = string[stringPos++]) && ch != delim)
  576.                     {
  577.                         setarg(paramPos, i++, ch);
  578.                     }
  579.                     if (!i)
  580.                     {
  581.                         return -1;
  582.                     }
  583.                 }
  584.                 else
  585.                 {
  586.                     while ((ch = string[stringPos++]))
  587.                     {
  588.                         setarg(paramPos, i++, ch);
  589.                     }
  590.                 }
  591.                 stringPos--;
  592.                 setarg(paramPos, i, '\0');
  593.             }
  594.             default:
  595.             {
  596.                 continue;
  597.             }
  598.         }
  599.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  600.         {
  601.             stringPos++;
  602.         }
  603.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  604.         {
  605.             stringPos++;
  606.         }
  607.         paramPos++;
  608.     }
  609.     do
  610.     {
  611.         if ((delim = format[formatPos++]) > ' ')
  612.         {
  613.             if (delim == '\'')
  614.             {
  615.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  616.             }
  617.             else if (delim != 'z')
  618.             {
  619.                 return delim;
  620.             }
  621.         }
  622.     }
  623.     while (delim > ' ');
  624.     return 0;
  625. }
  626. // dutils... Credits: DracoBlue
  627. stock mktime(hour,minute,second,day,month,year) {
  628.     new timestamp2;
  629.  
  630.     timestamp2 = second + (minute * 60) + (hour * 3600);
  631.  
  632.     new days_of_month[12];
  633.  
  634.     if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) {
  635.             days_of_month = {31,29,31,30,31,30,31,31,30,31,30,31}; // Schaltjahr
  636.         } else {
  637.             days_of_month = {31,28,31,30,31,30,31,31,30,31,30,31}; // keins
  638.         }
  639.     new days_this_year = 0;
  640.     days_this_year = day;
  641.     if(month > 1) { // No January Calculation, because its always the 0 past months
  642.         for(new i=0; i<month-1;i++) {
  643.             days_this_year += days_of_month[i];
  644.         }
  645.     }
  646.     timestamp2 += days_this_year * 86400;
  647.  
  648.     for(new j=1970;j<year;j++) {
  649.         timestamp2 += 31536000;
  650.         if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) )  timestamp2 += 86400; // Schaltjahr + 1 Tag
  651.     }
  652.  
  653.     return timestamp2;
  654. }
  655. // Credits RyDeR`
  656. stock replaceChar(strSrc[], chWhat, chWith)
  657. {
  658.    for(new i; strSrc[i] != EOS; ++i)
  659.    {
  660.        if(strSrc[i] == chWhat)
  661.        {
  662.            strSrc[i] = chWith;
  663.        }
  664.    }
  665. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement