Advertisement
Guest User

Mysql Email v2

a guest
Mar 4th, 2011
910
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pawn 18.71 KB | None | 0 0
  1. /*********************\
  2.  Mysql E-mail system
  3.  Made by wups
  4. \*********************/
  5.  
  6. #include <a_samp>
  7. #include <a_mysql>
  8.  
  9. #define EMAIL_NAME "SA-MP.com" // change this to anything you want. Now it would be Name@SA-MP.com
  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
  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@"#EMAIL_NAME"' 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@"#EMAIL_NAME"' 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.     switch(dialogid)
  129.     {
  130.         case DIALOGID-1: // reply/delete
  131.         {
  132.             if(response)
  133.             {
  134.                 ShowPlayerDialog(playerid,DIALOGID+31,DIALOG_STYLE_INPUT,"Compose","Input the Subject.\nMax Lenght: 100 symbols.","Ok","Back");
  135.                 return 1;
  136.             }
  137.             else
  138.             {
  139.                 new query[128];
  140.                 format(query,sizeof(query),"DELETE FROM `Emails` WHERE MK=%i LIMIT 1",MkP[playerid]);
  141.                 QUERY(query);
  142.                 SendClientMessage(playerid,0xFFFFFF30," * Message deleted!");
  143.                 ShowEmail(playerid);
  144.                 return 1;
  145.             }
  146.         }
  147.         case DIALOGID-2:
  148.         {
  149.             if(!response) ShowEmail(playerid);
  150.             return 1;
  151.         }
  152.         case DIALOGID+1: // inbox
  153.         {
  154.             if(response)
  155.             {
  156.                 new result[1024],
  157.                     name[MAX_PLAYER_NAME],
  158.                     Subject[100],
  159.                     Sender[60],
  160.                     Time[15],
  161.                     Date[20],
  162.                     Message[256],
  163.                     New=0,
  164.                     Mk;
  165.  
  166.                 GetPlayerName(playerid,name,MAX_PLAYER_NAME);
  167.                 format(result,sizeof(result),"SELECT `Sender`,`Subject`,`Time`,`Date`,`New`,`MK`,`Text` FROM `Emails` WHERE `Reciever`='%s@"#EMAIL_NAME"' ORDER BY `MK` DESC LIMIT %i,1",name,listitem);
  168.                 QUERY(result);
  169.                 STORE;
  170.                 mysql_fetch_row_format(result,"|",mysql_connection);
  171.                 sscanf(result,"ssssiis",Sender,Subject,Time,Date,New,Mk,Message);
  172.                 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);
  173.                 FREE;
  174.                
  175.                 format(RecieverP[playerid],60,"%s@"#EMAIL_NAME,Sender);
  176.                 MkP[playerid]=Mk;
  177.                 ShowPlayerDialog(playerid,DIALOGID-1,DIALOG_STYLE_MSGBOX,"Message",result,"Reply","Delete");
  178.                 if(New)
  179.                 {
  180.                     format(result,sizeof(result),"UPDATE `Emails` SET `New`=0 WHERE `MK`='%i' LIMIT 1",Mk);
  181.                     QUERY(result);
  182.                 }
  183.             }
  184.             return 1;
  185.         }
  186.         case DIALOGID+2: // outbox
  187.         {
  188.             if(response)
  189.             {
  190.                 new result[1024],
  191.                     name[MAX_PLAYER_NAME],
  192.                     Subject[100],
  193.                     Reciever[60],
  194.                     Time[15],
  195.                     Date[20],
  196.                     Message[256];
  197.  
  198.                 GetPlayerName(playerid,name,MAX_PLAYER_NAME);
  199.                 format(result,sizeof(result),"SELECT `Reciever`,`Subject`,`Time`,`Date`,`Text` FROM `Emails` WHERE `Sender`='%s@"#EMAIL_NAME"' ORDER BY `MK` DESC LIMIT %i,1",name,listitem);
  200.                 QUERY(result);
  201.                 STORE;
  202.                 mysql_fetch_row_format(result,"|",mysql_connection);
  203.                 sscanf(result,"sssss",Reciever,Subject,Time,Date,Message);
  204.                 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);
  205.                 FREE;
  206.                 ShowPlayerDialog(playerid,DIALOGID-2,DIALOG_STYLE_MSGBOX,"Message",result,"Ok","Cancel");
  207.             }
  208.             return 1;
  209.         }
  210.         case DIALOGID: // main dialog
  211.         {
  212.             if(response)
  213.             {
  214.                 switch(listitem)
  215.                 {
  216.                     case 0: // inbox
  217.                     {
  218.                         new result[3048],
  219.                             name[MAX_PLAYER_NAME],
  220.                             QR[256],
  221.                             Subject[100],
  222.                             Sender[60],
  223.                             Time[10],
  224.                             New
  225.                             ;
  226.                         GetPlayerName(playerid,name,MAX_PLAYER_NAME);
  227.                         format(QR,sizeof(QR),"SELECT `Sender`,`Subject`,`Time`,`New` FROM `Emails` WHERE `Reciever`='%s@"#EMAIL_NAME"' ORDER BY `MK` DESC LIMIT 20",name);
  228.                         QUERY(QR);
  229.                         STORE;
  230.                         if(!ROWS) return SendClientMessage(playerid,0xFFFFFF30," * You don't have any messages in your inbox!");
  231.                         while(mysql_fetch_row_format(QR,"|",mysql_connection))
  232.                         {
  233.                             sscanf(QR,"sssi",Sender,Subject,Time,New);
  234.                             if(!New)
  235.                                 format(result,sizeof(result),"%s{FFFFFF}'%s'{FF9933} FROM %s{FFFF33} %s\n",result,Subject,Sender,Time);
  236.                             else
  237.                                 format(result,sizeof(result),"%s{FFFFFF}'%s'{FF9933} FROM %s{FFFF33} NEW\n",result,Subject,Sender);
  238.  
  239.                         }
  240.                         FREE;
  241.                         ShowPlayerDialog(playerid,DIALOGID+1,DIALOG_STYLE_LIST,"Inbox",result,"Ok","Back");
  242.                         return 1;
  243.                     }
  244.                    case 1: // outbox
  245.                     {
  246.                         new result[3048],
  247.                             name[MAX_PLAYER_NAME],
  248.                             QR[256],
  249.                             Subject[100],
  250.                             Reciever[60],
  251.                             Time[10],
  252.                             New
  253.                             ;
  254.                         GetPlayerName(playerid,name,MAX_PLAYER_NAME);
  255.                         format(QR,sizeof(QR),"SELECT `Reciever`,`Subject`,`Time`,`New` FROM `Emails` WHERE `Sender`='%s@"#EMAIL_NAME"' ORDER BY `MK` DESC LIMIT 20",name);
  256.                         QUERY(QR);
  257.                         STORE;
  258.                         if(!ROWS) return SendClientMessage(playerid,0xFFFFFF30," * You don't have any messages in your outbox!");
  259.                         while(mysql_fetch_row_format(QR,"|",mysql_connection))
  260.                         {
  261.                             sscanf(QR,"sssi",Reciever,Subject,Time,New);
  262.                             if(!New)
  263.                                 format(result,sizeof(result),"%s{FFFFFF}'%s'{FF9933} TO %s{FFFF33} %s\n",result,Subject,Reciever,Time);
  264.                             else
  265.                                 format(result,sizeof(result),"%s{FFFFFF}'%s'{FF9933} TO %s{FFFF33} UNREAD\n",result,Subject,Reciever);
  266.                         }
  267.                         FREE;
  268.                         ShowPlayerDialog(playerid,DIALOGID+2,DIALOG_STYLE_LIST,"Outbox",result,"Ok","Back");
  269.                         return 1;
  270.                     }
  271.                     case 2: // compose
  272.                     {
  273.                         ShowPlayerDialog(playerid,DIALOGID+30,DIALOG_STYLE_INPUT,"Compose","Input the Recipients E-Mail address.\nFormat - Name@"#EMAIL_NAME,"Ok","Back");
  274.                         return 1;
  275.                     }
  276.                 }
  277.             }
  278.         }
  279.         case DIALOGID+30: // compose 1
  280.         {
  281.             if(response)
  282.             {
  283.                 if(strlen(inputtext) > 50 || strlen(inputtext) < strlen(EMAIL_NAME)+2 || strfind(inputtext,"@"#EMAIL_NAME,true) != -1 || !ValidEmail(inputtext)  || strfind(inputtext,"|",true) != -1 ) return ShowPlayerDialog(playerid,DIALOGID+30,DIALOG_STYLE_INPUT,"Compose","Input the Recipients E-Mail address.\nFormat - Name@"#EMAIL_NAME".\nE-Mail address Name is in wrong format!","Ok","Back");
  284.                 format(RecieverP[playerid],50,inputtext);
  285.                 ShowPlayerDialog(playerid,DIALOGID+31,DIALOG_STYLE_INPUT,"Compose","Input the Subject.\nMax Lenght: 100 symbols.","Ok","Back");
  286.                 return 1;
  287.             }
  288.             else
  289.             {
  290.                ShowEmail(playerid);
  291.                return 1;
  292.             }
  293.         }
  294.         case DIALOGID+31: // compose 2
  295.         {
  296.             if(response)
  297.             {
  298.                 if(strlen(inputtext) > 98 || strlen(inputtext) < 2 || strfind(inputtext,"\n",true)  != -1 || strfind(inputtext,"'",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");
  299.                 format(SubjectP[playerid],100,inputtext);
  300.                 ShowPlayerDialog(playerid,DIALOGID+32,DIALOG_STYLE_INPUT,"Compose","Write the message.\nMax Lenght: 256 symbols.","Ok","Back");
  301.                 return 1;
  302.             }
  303.             else
  304.             {
  305.                ShowEmail(playerid);
  306.                return 1;
  307.             }
  308.         }
  309.         case DIALOGID+32: // compose 3
  310.         {
  311.             if(response)
  312.             {
  313.                 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");
  314.                 if(strfind(inputtext,"\n",true)  != -1 || strfind(inputtext,"'",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");
  315.                 new
  316.                     query[1024],
  317.                     hour,
  318.                     minute,
  319.                     second,
  320.                     day,
  321.                     month,
  322.                     year,
  323.                     mk,
  324.                     name[MAX_PLAYER_NAME];
  325.                    
  326.                 gettime(hour,minute,second);
  327.                 getdate(year,month,day);
  328.                 mk = mktime(hour,minute,second,day,month,year);
  329.                 GetPlayerName(playerid,name,MAX_PLAYER_NAME);
  330.                 format(query,sizeof(query),"INSERT INTO `Emails` (Sender,Reciever,Date,Time,MK,New,Subject,Text) VALUES('%s@"#EMAIL_NAME"','%s','%i-%i-%i','%i:%i',%i,1,'%s','%s')",
  331.                                                                 name,RecieverP[playerid],day,month,year,hour,minute,mk,SubjectP[playerid],inputtext);
  332.                 QUERY(query);
  333.                 SendClientMessage(playerid,0xFFFFFF30," * Message sent!");
  334.                 return 1;
  335.             }
  336.             else
  337.             {
  338.                ShowEmail(playerid);
  339.                return 1;
  340.             }
  341.         }
  342.    }
  343.     return 0;
  344. }
  345.  
  346. // Libraries
  347. stock sscanf(string[], format[], {Float,_}:...) // credits Y_Less
  348. {
  349.     #if defined isnull
  350.         if (isnull(string))
  351.     #else
  352.         if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
  353.     #endif
  354.         {
  355.             return format[0];
  356.         }
  357.     #pragma tabsize 4
  358.     new
  359.         formatPos = 0,
  360.         stringPos = 0,
  361.         paramPos = 2,
  362.         paramCount = numargs(),
  363.         delim = '|';
  364.     while (string[stringPos] && string[stringPos] <= ' ')
  365.     {
  366.         stringPos++;
  367.     }
  368.     while (paramPos < paramCount && string[stringPos])
  369.     {
  370.         switch (format[formatPos++])
  371.         {
  372.             case '\0':
  373.             {
  374.                 return 0;
  375.             }
  376.             case 'i':
  377.             {
  378.                 new
  379.                     neg = 1,
  380.                     num = 0,
  381.                     ch = string[stringPos];
  382.                 if (ch == '-')
  383.                 {
  384.                     neg = -1;
  385.                     ch = string[++stringPos];
  386.                 }
  387.                 do
  388.                 {
  389.                     stringPos++;
  390.                     if ('0' <= ch <= '9')
  391.                     {
  392.                         num = (num * 10) + (ch - '0');
  393.                     }
  394.                     else
  395.                     {
  396.                         return -1;
  397.                     }
  398.                 }
  399.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  400.                 setarg(paramPos, 0, num * neg);
  401.             }
  402.             case 'd':
  403.             {
  404.                 new
  405.                     num = 0,
  406.                     ch = string[stringPos];
  407.                 if (ch == '-')
  408.                 {
  409.                     return -1;
  410.                 }
  411.                 do
  412.                 {
  413.                     stringPos++;
  414.                     if ('0' <= ch <= '9')
  415.                     {
  416.                         num = (num * 10) + (ch - '0');
  417.                     }
  418.                     else
  419.                     {
  420.                         return -1;
  421.                     }
  422.                 }
  423.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  424.                 setarg(paramPos, 0, num);
  425.             }
  426.             case 'h', 'x':
  427.             {
  428.                 new
  429.                     num = 0,
  430.                     ch = string[stringPos];
  431.                 do
  432.                 {
  433.                     stringPos++;
  434.                     switch (ch)
  435.                     {
  436.                         case 'x', 'X':
  437.                         {
  438.                             num = 0;
  439.                             continue;
  440.                         }
  441.                         case '0' .. '9':
  442.                         {
  443.                             num = (num << 4) | (ch - '0');
  444.                         }
  445.                         case 'a' .. 'f':
  446.                         {
  447.                             num = (num << 4) | (ch - ('a' - 10));
  448.                         }
  449.                         case 'A' .. 'F':
  450.                         {
  451.                             num = (num << 4) | (ch - ('A' - 10));
  452.                         }
  453.                         default:
  454.                         {
  455.                             return -1;
  456.                         }
  457.                     }
  458.                 }
  459.                 while ((ch = string[stringPos]) > ' ' && ch != delim);
  460.                 setarg(paramPos, 0, num);
  461.             }
  462.             case 'c':
  463.             {
  464.                 setarg(paramPos, 0, string[stringPos++]);
  465.             }
  466.             case 'f':
  467.             {
  468.  
  469.                 new changestr[16], changepos = 0, strpos = stringPos;
  470.                 while(changepos < 16 && string[strpos] && string[strpos] != delim)
  471.                 {
  472.                     changestr[changepos++] = string[strpos++];
  473.                     }
  474.                 changestr[changepos] = '\0';
  475.                 setarg(paramPos,0,_:floatstr(changestr));
  476.             }
  477.             case 'p':
  478.             {
  479.                 delim = format[formatPos++];
  480.                 continue;
  481.             }
  482.             case '\'':
  483.             {
  484.                 new
  485.                     end = formatPos - 1,
  486.                     ch;
  487.                 while ((ch = format[++end]) && ch != '\'') {}
  488.                 if (!ch)
  489.                 {
  490.                     return -1;
  491.                 }
  492.                 format[end] = '\0';
  493.                 if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
  494.                 {
  495.                     if (format[end + 1])
  496.                     {
  497.                         return -1;
  498.                     }
  499.                     return 0;
  500.                 }
  501.                 format[end] = '\'';
  502.                 stringPos = ch + (end - formatPos);
  503.                 formatPos = end + 1;
  504.             }
  505.             case 'u':
  506.             {
  507.                 new
  508.                     end = stringPos - 1,
  509.                     id = 0,
  510.                     bool:num = true,
  511.                     ch;
  512.                 while ((ch = string[++end]) && ch != delim)
  513.                 {
  514.                     if (num)
  515.                     {
  516.                         if ('0' <= ch <= '9')
  517.                         {
  518.                             id = (id * 10) + (ch - '0');
  519.                         }
  520.                         else
  521.                         {
  522.                             num = false;
  523.                         }
  524.                     }
  525.                 }
  526.                 if (num && IsPlayerConnected(id))
  527.                 {
  528.                     setarg(paramPos, 0, id);
  529.                 }
  530.                 else
  531.                 {
  532.                     #if !defined foreach
  533.                         #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
  534.                         #define __SSCANF_FOREACH__
  535.                     #endif
  536.                     string[end] = '\0';
  537.                     num = false;
  538.                     new
  539.                         name[MAX_PLAYER_NAME];
  540.                     id = end - stringPos;
  541.                     foreach (Player, playerid)
  542.                     {
  543.                         GetPlayerName(playerid, name, sizeof (name));
  544.                         if (!strcmp(name, string[stringPos], true, id))
  545.                         {
  546.                             setarg(paramPos, 0, playerid);
  547.                             num = true;
  548.                             break;
  549.                         }
  550.                     }
  551.                     if (!num)
  552.                     {
  553.                         setarg(paramPos, 0, INVALID_PLAYER_ID);
  554.                     }
  555.                     string[end] = ch;
  556.                     #if defined __SSCANF_FOREACH__
  557.                         #undef foreach
  558.                         #undef __SSCANF_FOREACH__
  559.                     #endif
  560.                 }
  561.                 stringPos = end;
  562.             }
  563.             case 's', 'z':
  564.             {
  565.                 new
  566.                     i = 0,
  567.                     ch;
  568.                 if (format[formatPos])
  569.                 {
  570.                     while ((ch = string[stringPos++]) && ch != delim)
  571.                     {
  572.                         setarg(paramPos, i++, ch);
  573.                     }
  574.                     if (!i)
  575.                     {
  576.                         return -1;
  577.                     }
  578.                 }
  579.                 else
  580.                 {
  581.                     while ((ch = string[stringPos++]))
  582.                     {
  583.                         setarg(paramPos, i++, ch);
  584.                     }
  585.                 }
  586.                 stringPos--;
  587.                 setarg(paramPos, i, '\0');
  588.             }
  589.             default:
  590.             {
  591.                 continue;
  592.             }
  593.         }
  594.         while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
  595.         {
  596.             stringPos++;
  597.         }
  598.         while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
  599.         {
  600.             stringPos++;
  601.         }
  602.         paramPos++;
  603.     }
  604.     do
  605.     {
  606.         if ((delim = format[formatPos++]) > ' ')
  607.         {
  608.             if (delim == '\'')
  609.             {
  610.                 while ((delim = format[formatPos++]) && delim != '\'') {}
  611.             }
  612.             else if (delim != 'z')
  613.             {
  614.                 return delim;
  615.             }
  616.         }
  617.     }
  618.     while (delim > ' ');
  619.     return 0;
  620. }
  621. // dutils... Credits: DracoBlue
  622. stock mktime(hour,minute,second,day,month,year) {
  623.     new timestamp2;
  624.  
  625.     timestamp2 = second + (minute * 60) + (hour * 3600);
  626.  
  627.     new days_of_month[12];
  628.  
  629.     if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) {
  630.             days_of_month = {31,29,31,30,31,30,31,31,30,31,30,31}; // Schaltjahr
  631.         } else {
  632.             days_of_month = {31,28,31,30,31,30,31,31,30,31,30,31}; // keins
  633.         }
  634.     new days_this_year = 0;
  635.     days_this_year = day;
  636.     if(month > 1) { // No January Calculation, because its always the 0 past months
  637.         for(new i=0; i<month-1;i++) {
  638.             days_this_year += days_of_month[i];
  639.         }
  640.     }
  641.     timestamp2 += days_this_year * 86400;
  642.  
  643.     for(new j=1970;j<year;j++) {
  644.         timestamp2 += 31536000;
  645.         if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) )  timestamp2 += 86400; // Schaltjahr + 1 Tag
  646.     }
  647.  
  648.     return timestamp2;
  649. }
  650.  
  651. stock ValidEmail(email[]) {
  652.  new len=strlen(email);
  653.  new cstate=0;
  654.  new i;
  655.  for(i=0;i<len;i++) {
  656.    if ((cstate==0 || cstate==1) && (email[i]>='A' && email[i]<='Z') || (email[i]>='a' && email[i]<='z')  || (email[i]=='.')  || (email[i]=='-')  || (email[i]=='_'))
  657.    {
  658.    } else {
  659.       // Ok no A..Z,a..z,_,.,-
  660.       if ((cstate==0) &&(email[i]=='@')) {
  661.          // its an @ after the name, ok state=1;
  662.          cstate=1;
  663.       } else {
  664.          // Its stuff which is not allowed
  665.          return false;
  666.       }
  667.    }
  668.  }
  669.  if (cstate<1) return false;
  670.  if (len<6) return false;
  671.  // A toplevel domain has only 3 to 4 signs :-)
  672.  if ((email[len-3]=='.') || (email[len-4]=='.') || (email[len-5]=='.')) return true;
  673.  return false;
  674. }
  675. // strlib.. Credits Westie. Not needed until next version
  676. /*
  677. stock str_replace(sSearch[], sReplace[], const sSubject[], &iCount = 0)
  678. {
  679.     new
  680.         iLengthTarget = strlen(sSearch),
  681.         iLengthReplace = strlen(sReplace),
  682.         iLengthSource = strlen(sSubject),
  683.         iItterations = (iLengthSource - iLengthTarget) + 1;
  684.  
  685.     new
  686.         sTemp[1024],
  687.         sReturn[1024];
  688.  
  689.     strcat(sReturn, sSubject, 1024);
  690.     iCount = 0;
  691.  
  692.     for(new iIndex; iIndex < iItterations; ++iIndex)
  693.     {
  694.         strmid(sTemp, sReturn, iIndex, (iIndex + iLengthTarget), (iLengthTarget + 1));
  695.  
  696.         if(!strcmp(sTemp, sSearch, false))
  697.         {
  698.             strdel(sReturn, iIndex, (iIndex + iLengthTarget));
  699.             strins(sReturn, sReplace, iIndex, iLengthReplace);
  700.  
  701.             iIndex += iLengthTarget;
  702.             iCount++;
  703.         }
  704.     }
  705.  
  706.     return sReturn;
  707. }
  708. */
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement