Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*********************\
- Mysql E-mail system
- Made by wups
- Version 1.0
- \*********************/
- #include <a_samp>
- #include <a_mysql>
- // You must configure these!
- #define SQL_IP ""
- #define SQL_USER ""
- #define SQL_PASSWORD ""
- #define SQL_DB ""
- // End
- // defines (ignore them)
- #define QUERY(%0) mysql_query(%0, -1, -1, mysql_connection)
- #define CREATE_QUERY "CREATE TABLE IF NOT EXISTS `Emails`( \
- `Sender` varchar(100) NOT NULL,`Reciever` varchar(100) NOT NULL, \
- `Date` varchar(24) NOT NULL,`Time` varchar(24) NOT NULL,`MK` int(11) NOT NULL, \
- `New` smallint(6) NOT NULL,`Subject` varchar(100) NOT NULL,`Text` mediumtext NOT NULL) \
- ENGINE=MyISAM DEFAULT CHARSET=latin1 \
- COLLATE=latin1_general_cs AUTO_INCREMENT=1"
- #define DIALOGID 7654
- #define FREE mysql_free_result(mysql_connection)
- #define STORE mysql_store_result(mysql_connection)
- #define ROWS mysql_num_rows(mysql_connection)
- // variables
- static mysql_connection;
- new SubjectP[MAX_PLAYERS][100],
- RecieverP[MAX_PLAYERS][50],
- MkP[MAX_PLAYERS];
- // functions
- public OnFilterScriptInit()
- {
- mysql_debug(1);
- mysql_connection = mysql_connect(SQL_IP, SQL_USER, SQL_DB, SQL_PASSWORD);
- QUERY(CREATE_QUERY);
- print("\n--------------------------------------");
- print(" Mysql E-Mail system by wups Loaded!");
- print("--------------------------------------\n");
- return 1;
- }
- public OnFilterScriptExit()
- {
- mysql_close(mysql_connection);
- print("\n--------------------------------------");
- print(" Mysql E-Mail system by wups Unloaded!");
- print("--------------------------------------\n");
- return 1;
- }
- public OnPlayerConnect(playerid)
- {
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- return 1;
- }
- public OnPlayerSpawn(playerid)
- {
- return 1;
- }
- public OnPlayerDeath(playerid, killerid, reason)
- {
- return 1;
- }
- public OnPlayerText(playerid, text[])
- {
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if(!strcmp("/email", cmdtext, true))
- {
- ShowEmail(playerid);
- return 1;
- }
- return 0;
- }
- stock ShowEmail(playerid)
- {
- new string[128],
- name[MAX_PLAYER_NAME],
- inbox,
- outbox;
- GetPlayerName(playerid,name,MAX_PLAYER_NAME);
- format(string,sizeof(string),"SELECT `New` FROM `Emails` WHERE `Reciever`='%s' AND `New`=1",name);
- QUERY(string);
- STORE;
- inbox = ROWS;
- FREE;
- format(string,sizeof(string),"SELECT `New` FROM `Emails` WHERE `Sender`='%s' AND `New`=1",name);
- QUERY(string);
- STORE;
- outbox = ROWS;
- FREE;
- format(string,sizeof(string),"{FFFFFF}\
- Inbox({FF0000}%i{FFFFFF} New)\n\
- Outbox({FF0000}%i{FFFFFF} Unread)\n\
- Compose",inbox,outbox);
- ShowPlayerDialog(playerid, DIALOGID, DIALOG_STYLE_LIST,"E-Mail",string,"Ok","Cancel");
- return 1;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- mysql_real_escape_string(inputtext,inputtext);
- switch(dialogid)
- {
- case DIALOGID-1: // reply/delete
- {
- if(response)
- {
- ShowPlayerDialog(playerid,DIALOGID+31,DIALOG_STYLE_INPUT,"Compose","Input the Subject.\nMax Lenght: 100 symbols.","Ok","Back");
- return 1;
- }
- else
- {
- new query[128];
- format(query,sizeof(query),"DELETE FROM `Emails` WHERE MK=%i LIMIT 1",MkP[playerid]);
- QUERY(query);
- SendClientMessage(playerid,0xFFFFFF30," * Message deleted!");
- ShowEmail(playerid);
- return 1;
- }
- }
- case DIALOGID-2:
- {
- ShowEmail(playerid);
- return 1;
- }
- case DIALOGID+1: // inbox
- {
- if(response)
- {
- new result[1024],
- name[MAX_PLAYER_NAME],
- Subject[100],
- Sender[60],
- Time[15],
- Date[20],
- Message[256],
- New=0,
- Mk;
- GetPlayerName(playerid,name,MAX_PLAYER_NAME);
- 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);
- QUERY(result);
- STORE;
- mysql_fetch_row_format(result,"|",mysql_connection);
- sscanf(result,"ssssiis",Sender,Subject,Time,Date,New,Mk,Message);
- replaceChar(Message,'~','\n');
- 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);
- FREE;
- format(RecieverP[playerid],60,"%s",Sender);
- MkP[playerid]=Mk;
- ShowPlayerDialog(playerid,DIALOGID-1,DIALOG_STYLE_MSGBOX,"Message",result,"Reply","Delete");
- if(New)
- {
- format(result,sizeof(result),"UPDATE `Emails` SET `New`=0 WHERE `MK`='%i' LIMIT 1",Mk);
- QUERY(result);
- }
- }
- else ShowEmail(playerid);
- return 1;
- }
- case DIALOGID+2: // outbox
- {
- if(response)
- {
- new result[1024],
- name[MAX_PLAYER_NAME],
- Subject[100],
- Reciever[60],
- Time[15],
- Date[20],
- Message[256];
- GetPlayerName(playerid,name,MAX_PLAYER_NAME);
- format(result,sizeof(result),"SELECT `Reciever`,`Subject`,`Time`,`Date`,`Text` FROM `Emails` WHERE `Sender`='%s' ORDER BY `MK` DESC LIMIT %i,1",name,listitem);
- QUERY(result);
- STORE;
- mysql_fetch_row_format(result,"|",mysql_connection);
- sscanf(result,"sssss",Reciever,Subject,Time,Date,Message);
- 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);
- FREE;
- ShowPlayerDialog(playerid,DIALOGID-2,DIALOG_STYLE_MSGBOX,"Message",result,"Ok","Cancel");
- }
- else ShowEmail(playerid);
- return 1;
- }
- case DIALOGID: // main dialog
- {
- if(response)
- {
- switch(listitem)
- {
- case 0: // inbox
- {
- new result[3048],
- name[MAX_PLAYER_NAME],
- QR[256],
- Subject[100],
- Sender[60],
- Time[10],
- New
- ;
- GetPlayerName(playerid,name,MAX_PLAYER_NAME);
- format(QR,sizeof(QR),"SELECT `Sender`,`Subject`,`Time`,`New` FROM `Emails` WHERE `Reciever`='%s' ORDER BY `MK` DESC LIMIT 20",name);
- QUERY(QR);
- STORE;
- if(!ROWS) return SendClientMessage(playerid,0xFFFFFF30," * You don't have any messages in your inbox!");
- while(mysql_fetch_row_format(QR,"|",mysql_connection))
- {
- sscanf(QR,"sssi",Sender,Subject,Time,New);
- if(!New)
- format(result,sizeof(result),"%s{FFFFFF}'%s'{FF9933} FROM %s{FFFF33} %s\n",result,Subject,Sender,Time);
- else
- format(result,sizeof(result),"%s{FFFFFF}'%s'{FF9933} FROM %s{FFFF33} NEW\n",result,Subject,Sender);
- }
- FREE;
- ShowPlayerDialog(playerid,DIALOGID+1,DIALOG_STYLE_LIST,"Inbox",result,"Ok","Back");
- return 1;
- }
- case 1: // outbox
- {
- new result[3048],
- name[MAX_PLAYER_NAME],
- QR[256],
- Subject[100],
- Reciever[60],
- Time[10],
- New
- ;
- GetPlayerName(playerid,name,MAX_PLAYER_NAME);
- format(QR,sizeof(QR),"SELECT `Reciever`,`Subject`,`Time`,`New` FROM `Emails` WHERE `Sender`='%s' ORDER BY `MK` DESC LIMIT 20",name);
- QUERY(QR);
- STORE;
- if(!ROWS) return SendClientMessage(playerid,0xFFFFFF30," * You don't have any messages in your outbox!");
- while(mysql_fetch_row_format(QR,"|",mysql_connection))
- {
- sscanf(QR,"sssi",Reciever,Subject,Time,New);
- if(!New)
- format(result,sizeof(result),"%s{FFFFFF}'%s'{FF9933} TO %s{FFFF33} %s\n",result,Subject,Reciever,Time);
- else
- format(result,sizeof(result),"%s{FFFFFF}'%s'{FF9933} TO %s{FFFF33} UNREAD\n",result,Subject,Reciever);
- }
- FREE;
- ShowPlayerDialog(playerid,DIALOGID+2,DIALOG_STYLE_LIST,"Outbox",result,"Ok","Back");
- return 1;
- }
- case 2: // compose
- {
- ShowPlayerDialog(playerid,DIALOGID+30,DIALOG_STYLE_INPUT,"Compose","Input the Recipients E-Mail address.\nFormat - Name","Ok","Back");
- return 1;
- }
- }
- }
- }
- case DIALOGID+30: // compose 1
- {
- if(response)
- {
- 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");
- format(RecieverP[playerid],50,inputtext);
- ShowPlayerDialog(playerid,DIALOGID+31,DIALOG_STYLE_INPUT,"Compose","Input the Subject.\nMax Lenght: 100 symbols.","Ok","Back");
- return 1;
- }
- else
- {
- ShowEmail(playerid);
- return 1;
- }
- }
- case DIALOGID+31: // compose 2
- {
- if(response)
- {
- 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");
- format(SubjectP[playerid],100,inputtext);
- ShowPlayerDialog(playerid,DIALOGID+32,DIALOG_STYLE_INPUT,"Compose","Write the message.\nMax Lenght: 256 symbols.\n '~' Indicates a new line.","Ok","Back");
- return 1;
- }
- else
- {
- ShowEmail(playerid);
- return 1;
- }
- }
- case DIALOGID+32: // compose 3
- {
- if(response)
- {
- 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");
- 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");
- new
- query[1024],
- hour,
- minute,
- second,
- day,
- month,
- year,
- mk,
- name[MAX_PLAYER_NAME];
- gettime(hour,minute,second);
- getdate(year,month,day);
- mk = mktime(hour,minute,second,day,month,year);
- GetPlayerName(playerid,name,MAX_PLAYER_NAME);
- 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')",
- name,RecieverP[playerid],day,month,year,hour,minute,mk,SubjectP[playerid],inputtext);
- QUERY(query);
- SendClientMessage(playerid,0xFFFFFF30," * Message sent!");
- return 1;
- }
- else
- {
- ShowEmail(playerid);
- return 1;
- }
- }
- }
- return 0;
- }
- // Libraries
- stock sscanf(string[], format[], {Float,_}:...) // credits Y_Less
- {
- #if defined isnull
- if (isnull(string))
- #else
- if (string[0] == 0 || (string[0] == 1 && string[1] == 0))
- #endif
- {
- return format[0];
- }
- #pragma tabsize 4
- new
- formatPos = 0,
- stringPos = 0,
- paramPos = 2,
- paramCount = numargs(),
- delim = '|';
- while (string[stringPos] && string[stringPos] <= ' ')
- {
- stringPos++;
- }
- while (paramPos < paramCount && string[stringPos])
- {
- switch (format[formatPos++])
- {
- case '\0':
- {
- return 0;
- }
- case 'i':
- {
- new
- neg = 1,
- num = 0,
- ch = string[stringPos];
- if (ch == '-')
- {
- neg = -1;
- ch = string[++stringPos];
- }
- do
- {
- stringPos++;
- if ('0' <= ch <= '9')
- {
- num = (num * 10) + (ch - '0');
- }
- else
- {
- return -1;
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num * neg);
- }
- case 'd':
- {
- new
- num = 0,
- ch = string[stringPos];
- if (ch == '-')
- {
- return -1;
- }
- do
- {
- stringPos++;
- if ('0' <= ch <= '9')
- {
- num = (num * 10) + (ch - '0');
- }
- else
- {
- return -1;
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num);
- }
- case 'h', 'x':
- {
- new
- num = 0,
- ch = string[stringPos];
- do
- {
- stringPos++;
- switch (ch)
- {
- case 'x', 'X':
- {
- num = 0;
- continue;
- }
- case '0' .. '9':
- {
- num = (num << 4) | (ch - '0');
- }
- case 'a' .. 'f':
- {
- num = (num << 4) | (ch - ('a' - 10));
- }
- case 'A' .. 'F':
- {
- num = (num << 4) | (ch - ('A' - 10));
- }
- default:
- {
- return -1;
- }
- }
- }
- while ((ch = string[stringPos]) > ' ' && ch != delim);
- setarg(paramPos, 0, num);
- }
- case 'c':
- {
- setarg(paramPos, 0, string[stringPos++]);
- }
- case 'f':
- {
- new changestr[16], changepos = 0, strpos = stringPos;
- while(changepos < 16 && string[strpos] && string[strpos] != delim)
- {
- changestr[changepos++] = string[strpos++];
- }
- changestr[changepos] = '\0';
- setarg(paramPos,0,_:floatstr(changestr));
- }
- case 'p':
- {
- delim = format[formatPos++];
- continue;
- }
- case '\'':
- {
- new
- end = formatPos - 1,
- ch;
- while ((ch = format[++end]) && ch != '\'') {}
- if (!ch)
- {
- return -1;
- }
- format[end] = '\0';
- if ((ch = strfind(string, format[formatPos], false, stringPos)) == -1)
- {
- if (format[end + 1])
- {
- return -1;
- }
- return 0;
- }
- format[end] = '\'';
- stringPos = ch + (end - formatPos);
- formatPos = end + 1;
- }
- case 'u':
- {
- new
- end = stringPos - 1,
- id = 0,
- bool:num = true,
- ch;
- while ((ch = string[++end]) && ch != delim)
- {
- if (num)
- {
- if ('0' <= ch <= '9')
- {
- id = (id * 10) + (ch - '0');
- }
- else
- {
- num = false;
- }
- }
- }
- if (num && IsPlayerConnected(id))
- {
- setarg(paramPos, 0, id);
- }
- else
- {
- #if !defined foreach
- #define foreach(%1,%2) for (new %2 = 0; %2 < MAX_PLAYERS; %2++) if (IsPlayerConnected(%2))
- #define __SSCANF_FOREACH__
- #endif
- string[end] = '\0';
- num = false;
- new
- name[MAX_PLAYER_NAME];
- id = end - stringPos;
- foreach (Player, playerid)
- {
- GetPlayerName(playerid, name, sizeof (name));
- if (!strcmp(name, string[stringPos], true, id))
- {
- setarg(paramPos, 0, playerid);
- num = true;
- break;
- }
- }
- if (!num)
- {
- setarg(paramPos, 0, INVALID_PLAYER_ID);
- }
- string[end] = ch;
- #if defined __SSCANF_FOREACH__
- #undef foreach
- #undef __SSCANF_FOREACH__
- #endif
- }
- stringPos = end;
- }
- case 's', 'z':
- {
- new
- i = 0,
- ch;
- if (format[formatPos])
- {
- while ((ch = string[stringPos++]) && ch != delim)
- {
- setarg(paramPos, i++, ch);
- }
- if (!i)
- {
- return -1;
- }
- }
- else
- {
- while ((ch = string[stringPos++]))
- {
- setarg(paramPos, i++, ch);
- }
- }
- stringPos--;
- setarg(paramPos, i, '\0');
- }
- default:
- {
- continue;
- }
- }
- while (string[stringPos] && string[stringPos] != delim && string[stringPos] > ' ')
- {
- stringPos++;
- }
- while (string[stringPos] && (string[stringPos] == delim || string[stringPos] <= ' '))
- {
- stringPos++;
- }
- paramPos++;
- }
- do
- {
- if ((delim = format[formatPos++]) > ' ')
- {
- if (delim == '\'')
- {
- while ((delim = format[formatPos++]) && delim != '\'') {}
- }
- else if (delim != 'z')
- {
- return delim;
- }
- }
- }
- while (delim > ' ');
- return 0;
- }
- // dutils... Credits: DracoBlue
- stock mktime(hour,minute,second,day,month,year) {
- new timestamp2;
- timestamp2 = second + (minute * 60) + (hour * 3600);
- new days_of_month[12];
- if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) {
- days_of_month = {31,29,31,30,31,30,31,31,30,31,30,31}; // Schaltjahr
- } else {
- days_of_month = {31,28,31,30,31,30,31,31,30,31,30,31}; // keins
- }
- new days_this_year = 0;
- days_this_year = day;
- if(month > 1) { // No January Calculation, because its always the 0 past months
- for(new i=0; i<month-1;i++) {
- days_this_year += days_of_month[i];
- }
- }
- timestamp2 += days_this_year * 86400;
- for(new j=1970;j<year;j++) {
- timestamp2 += 31536000;
- if ( ((year % 4 == 0) && (year % 100 != 0)) || (year % 400 == 0) ) timestamp2 += 86400; // Schaltjahr + 1 Tag
- }
- return timestamp2;
- }
- // Credits RyDeR`
- stock replaceChar(strSrc[], chWhat, chWith)
- {
- for(new i; strSrc[i] != EOS; ++i)
- {
- if(strSrc[i] == chWhat)
- {
- strSrc[i] = chWith;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement