Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <a_samp>
- #include <irc>
- #if defined MAX_PLAYERS
- #undef MAX_PLAYERS
- #endif
- #define MAX_PLAYERS (200) // Slot's
- #define MAX_MESSAGE (20) // Max. save message
- #define MAX_MESSAGE_STRING (74) /* max message len + 24 nick
- (50 + 24 )*/
- #define IRC_LIST (0) // List's ID 1
- #define IRC_CHANNEL_NAME (1) // List's ID 2
- #define IRC_CHANNEL_PASS (2) // List's ID 3
- #define IRC_CHANNEL_DEL (3) // List's ID 4
- #define IRC_CHANNEL_JOIN (4) // List's ID 5
- #define IRC_CHANNEL_PASS2 (5) // List's ID 6
- #define IRC_MESSAGE (6) // List's ID 7
- #define IRC_MESSAGE_SEND (7) // List's ID 8
- #define IRC_CHANNEL_DELETE (8) // List's ID 9
- #define IRC_CHANNEL_MSGBOX (9) // List's ID 10
- #define IRC_MESSAGE_MSGBOX (10) // List's ID 11
- #define MAX_CHANNELS (21) // Max channels
- #define MAX_CHANNELS_NAME (10) // Max channel's name len
- #define MAX_CHANNELS_PASS (10) // Max channel's pass len
- #define COLOR_GREEN (0x00CC00FF)
- #define COLOR_RED (0xCC0000FF)
- #define COLOR_YELLOW (0xC5FF3EFF)
- #define COLOR_ORANGE (0xFF9600FF)
- #define Print(%1) { \
- print(\
- "\nIRC's Channel system by Gertin/\x44\x65\x73\x74\x72\x6f\x6a\x65\x72\n");}
- enum pInfo
- {
- ircChannel,
- ircJoin,
- createChannel,
- bool:windowOpen
- }
- enum channels
- {
- names[MAX_CHANNELS_NAME],
- pass[MAX_CHANNELS_PASS],
- message,
- bool:active,
- bool:havePassword
- }
- new
- playerInfo[MAX_PLAYERS][pInfo],
- ircChannels[MAX_CHANNELS][channels],
- chatHistory[MAX_CHANNELS][MAX_MESSAGE][MAX_MESSAGE_STRING];
- stock PlayerName(playerid)
- {
- new name[24];
- GetPlayerName(playerid, name, sizeof(name));
- return name;
- }
- public OnFilterScriptInit()
- {
- Print("IRC's Channel system by Gertin/Iron Smith")
- return 1;
- }
- public OnFilterScriptExit()
- {
- print("Filter Script unloaded");
- return 1;
- }
- public OnPlayerDisconnect(playerid, reason)
- {
- if(playerInfo[playerid][createChannel] != 0)
- {
- ircChannels[playerInfo[playerid][createChannel]][active] = false;
- strdel(ircChannels[playerInfo[playerid][createChannel]][names], 0, 10);
- strdel(ircChannels[playerInfo[playerid][createChannel]][pass], 0, 10);
- for(new i = 1; i < MAX_MESSAGE; i++)
- strdel(chatHistory[playerInfo[playerid][createChannel]][i], 0,
- MAX_MESSAGE_STRING);
- for(new i, gmax = GetMaxPlayers(); i < gmax; i++)
- {
- if(!IsPlayerConnected(i))
- continue;
- if(playerInfo[i][ircChannel] == playerInfo[playerid][ircChannel])
- {
- ShowPlayerDialog(playerid, IRC_CHANNEL_MSGBOX,
- DIALOG_STYLE_MSGBOX,
- "Disconnected",
- "Channel was deleted!",
- "OK",
- "Close");
- playerInfo[i][ircChannel] = 0;
- }
- }
- playerInfo[playerid][createChannel] = 0;
- }
- playerInfo[playerid][ircChannel] = 0;
- return 1;
- }
- public OnPlayerCommandText(playerid, cmdtext[])
- {
- if (strcmp(cmdtext[1], "ircoptions", true) == 0)
- {
- #define TITLE "Select option"
- #define OPTIONS "Create channel\nDelete/Leave\nJoin"
- ShowPlayerDialog(playerid, IRC_LIST, DIALOG_STYLE_LIST, TITLE, OPTIONS,
- "Next",
- "Close");
- return 1;
- }
- if (strcmp(cmdtext[1], "irc", true) == 0)
- {
- new strTitle[45], strChat[2500];
- if(playerInfo[playerid][ircChannel] == 0)
- return SendClientMessage(playerid, COLOR_RED,
- "You are not in any irc channel!");
- format(strTitle, sizeof(strTitle),
- "Channel #%s",
- ircChannels[playerInfo[playerid][ircChannel]][names]);
- for(new i = 1; i < MAX_MESSAGE; i++)
- {
- if(!strlen(chatHistory[playerInfo[playerid][ircChannel]][i]))
- continue;
- strcat(strChat, chatHistory[playerInfo[playerid][ircChannel]][i],
- sizeof(strChat));
- }
- if(!strlen(strChat))
- {
- ShowPlayerDialog(playerid, IRC_MESSAGE, DIALOG_STYLE_LIST, strTitle,
- "No message",
- "Write",
- "Hide");
- return 1;
- }
- ShowPlayerDialog(playerid, IRC_MESSAGE, DIALOG_STYLE_LIST, strTitle,
- strChat,
- "Write",
- "Hide");
- return 1;
- }
- return 0;
- }
- public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
- {
- if(dialogid == IRC_MESSAGE_MSGBOX)
- {
- new strTitle[45], strChat[2500];
- format(strTitle, sizeof(strTitle), "Channel #%s",
- ircChannels[playerInfo[playerid][ircChannel]][names]);
- for(new i = 1; i < MAX_MESSAGE; i++)
- {
- if(!strlen(chatHistory[playerInfo[playerid][ircChannel]][i]))
- continue;
- strcat(strChat, chatHistory[playerInfo[playerid][ircChannel]][i],
- sizeof(strChat));
- }
- playerInfo[playerid][windowOpen] = true;
- if(!strlen(strChat))
- {
- ShowPlayerDialog(playerid, IRC_MESSAGE, DIALOG_STYLE_LIST, strTitle,
- "No message",
- "Write",
- "Hide");
- return 1;
- }
- ShowPlayerDialog(playerid, IRC_MESSAGE, DIALOG_STYLE_LIST, strTitle,
- strChat,
- "Write",
- "Hide");
- return 1;
- }
- if(response == 1)
- {
- if(dialogid == IRC_LIST)
- {
- switch(listitem)
- {
- case 0:
- {
- if(playerInfo[playerid][createChannel] != 0)
- /*return SendClientMessage(playerid, COLOR_RED,
- "You have one channel. You can not have more!");*/
- for(new i = 1; i < MAX_CHANNELS; i++)
- {
- if(ircChannels[i][active] == false)
- {
- ShowPlayerDialog(playerid, IRC_CHANNEL_NAME,
- DIALOG_STYLE_INPUT,
- "Name",
- "",
- "Ok",
- "Cancel");
- playerInfo[playerid][createChannel] = i;
- return 1;
- }
- }
- }
- case 1:
- {
- new strChannels[220];
- for(new i = 1; i < MAX_CHANNELS; i++)
- {
- new str[20];
- format(str, sizeof(str), "\n#%s",
- ircChannels[i][names]);
- strcat(strChannels, str, sizeof(strChannels));
- }
- if(!strlen(ircChannels[1][names]))
- {
- ShowPlayerDialog(playerid, IRC_CHANNEL_MSGBOX,
- DIALOG_STYLE_MSGBOX,
- "Select channel",
- "No channels",
- "Ok",
- "Close");
- return 1;
- }
- ShowPlayerDialog(playerid, IRC_CHANNEL_DEL,
- DIALOG_STYLE_LIST,
- "Select channel",
- strChannels,
- "Delete",
- "Close");
- return 1;
- }
- case 2:
- {
- new strChannels[220];
- for(new i = 1; i < MAX_CHANNELS; i++)
- {
- new str[20];
- format(str, sizeof(str), "\n#%s",
- ircChannels[i][names]);
- strcat(strChannels, str, sizeof(strChannels));
- }
- if(!strlen(ircChannels[1][names]))
- {
- ShowPlayerDialog(playerid, IRC_CHANNEL_MSGBOX,
- DIALOG_STYLE_MSGBOX,
- "Select channel",
- "No channels",
- "Ok",
- "Close");
- return 1;
- }
- ShowPlayerDialog(playerid, IRC_CHANNEL_JOIN,
- DIALOG_STYLE_LIST,
- "Select channel",
- strChannels,
- "Join",
- "Close");
- return 1;
- }
- }
- return 1;
- }
- if(dialogid == IRC_CHANNEL_NAME)
- {
- if(strlen(inputtext) >= MAX_CHANNELS_NAME || strlen(inputtext) <= 1)
- {
- ShowPlayerDialog(playerid, IRC_CHANNEL_NAME, DIALOG_STYLE_INPUT,
- "Name",
- "",
- "Ok",
- "Cancel");
- SendClientMessage(playerid, COLOR_RED,
- "Wrong name!");
- return 1;
- }
- format(ircChannels[playerInfo[playerid][createChannel]][names],
- MAX_CHANNELS_NAME,
- "%s",
- inputtext);
- ircChannels[playerInfo[playerid][createChannel]][active] = true;
- ShowPlayerDialog(playerid, IRC_CHANNEL_PASS, DIALOG_STYLE_INPUT,
- "Password",
- "",
- "Ok",
- "NO PASS");
- return 1;
- }
- if(dialogid == IRC_CHANNEL_PASS)
- {
- new strInfo[45];
- if(strlen(inputtext) >= MAX_CHANNELS_PASS || strlen(inputtext) <= 1)
- {
- ShowPlayerDialog(playerid, IRC_CHANNEL_PASS, DIALOG_STYLE_INPUT,
- "Password",
- "",
- "Ok",
- "NO PASS");
- SendClientMessage(playerid, COLOR_RED,
- "Wrong password");
- return 1;
- }
- format(ircChannels[playerInfo[playerid][createChannel]][pass],
- MAX_CHANNELS_PASS,
- "%s",
- inputtext);
- format(strInfo, sizeof(strInfo), "Name: %s Password: %s",
- ircChannels[playerInfo[playerid][createChannel]][names],
- ircChannels[playerInfo[playerid][createChannel]][pass]);
- SendClientMessage(playerid, COLOR_GREEN, strInfo);
- SendClientMessage(playerid, COLOR_YELLOW,
- "Use /irc to open dialog window");
- playerInfo[playerid][ircChannel] = playerInfo[playerid][createChannel];
- return 1;
- }
- if(dialogid == IRC_CHANNEL_DEL)
- {
- if(ircChannels[(listitem + 1)][active] == false)
- {
- SendClientMessage(playerid, COLOR_RED,
- "Sorry the channel does no exist!");
- return 1;
- }
- if(strlen(ircChannels[playerInfo[playerid][createChannel]][pass]))
- {
- ShowPlayerDialog(playerid, IRC_CHANNEL_DELETE,
- DIALOG_STYLE_INPUT,
- "Password",
- "",
- "Ok",
- "Cancel");
- return 1;
- }
- if(!strlen(ircChannels[playerInfo[playerid][createChannel]][pass])
- && playerInfo[playerid][createChannel] != 0)
- {
- ircChannels[playerInfo[playerid][createChannel]][active] = false;
- strdel(ircChannels[playerInfo[playerid][createChannel]][names],
- 0,
- 10);
- strdel(ircChannels[playerInfo[playerid][createChannel]][pass],
- 0,
- 10);
- for(new i = 1; i < MAX_MESSAGE; i++)
- strdel(chatHistory[playerInfo[playerid][createChannel]][i],
- 0,
- MAX_MESSAGE_STRING);
- for(new i, gmax = GetMaxPlayers(); i < gmax; i++)
- {
- if(!IsPlayerConnected(i))
- continue;
- if(playerInfo[i][ircChannel] == playerInfo[playerid][ircChannel])
- {
- ShowPlayerDialog(playerid, IRC_CHANNEL_MSGBOX,
- DIALOG_STYLE_MSGBOX,
- "Disconnected",
- "Channel was deleted!",
- "OK",
- "Close");
- playerInfo[i][ircChannel] = 0;
- }
- }
- ircChannels[playerInfo[playerid][createChannel]][active] = false;
- strdel(ircChannels[playerInfo[playerid][createChannel]][names],
- 0,
- 10);
- strdel(ircChannels[playerInfo[playerid][createChannel]][pass],
- 0,
- 10);
- playerInfo[playerid][createChannel] = 0;
- SendClientMessage(playerid, COLOR_GREEN,
- "You deleted your IRC channel");
- return 1;
- }
- ShowPlayerDialog(playerid, IRC_CHANNEL_MSGBOX, DIALOG_STYLE_MSGBOX,
- "Information",
- "You are left channel",
- "Ok",
- "Close");
- playerInfo[playerid][ircChannel] = 0;
- return 1;
- }
- if(dialogid == IRC_CHANNEL_DELETE)
- {
- if(strcmp(ircChannels[playerInfo[playerid][createChannel]][pass],
- inputtext, false) == 0 && strlen(inputtext))
- {
- ircChannels[playerInfo[playerid][createChannel]][active] = false;
- strdel(ircChannels[playerInfo[playerid][createChannel]][names],
- 0,
- 10);
- strdel(ircChannels[playerInfo[playerid][createChannel]][pass],
- 0,
- 10);
- for(new i = 1; i < MAX_MESSAGE; i++)
- strdel(chatHistory[playerInfo[playerid][createChannel]][i],
- 0,
- MAX_MESSAGE_STRING);
- for(new i, gmax = GetMaxPlayers(); i < gmax; i++)
- {
- if(!IsPlayerConnected(i))
- continue;
- if(playerInfo[i][ircChannel] == playerInfo[playerid][ircChannel])
- {
- ShowPlayerDialog(playerid, IRC_CHANNEL_MSGBOX,
- DIALOG_STYLE_MSGBOX,
- "Disconnected",
- "Channel was deleted!",
- "OK",
- "Close");
- playerInfo[i][ircChannel] = 0;
- }
- }
- playerInfo[playerid][createChannel] = 0;
- SendClientMessage(playerid, COLOR_GREEN,
- "You deleted your IRC channel");
- return 1;
- }
- SendClientMessage(playerid, COLOR_RED, "Wrong password!");
- return 1;
- }
- if(dialogid == IRC_CHANNEL_JOIN)
- {
- if(ircChannels[(listitem + 1)][active] == false)
- {
- ShowPlayerDialog(playerid, IRC_CHANNEL_MSGBOX,
- DIALOG_STYLE_MSGBOX,
- "ERROR",
- "Channel does not exist!",
- "Ok",
- "Close");
- return 1;
- }
- if(!strlen(ircChannels[(listitem + 1)][pass]))
- {
- new strInfo[100];
- playerInfo[playerid][ircChannel] = (listitem + 1);
- format(strInfo, sizeof(strInfo), "You joined to %s channel",
- ircChannels[playerInfo[playerid][ircChannel]][names]);
- SendClientMessage(playerid, COLOR_GREEN, strInfo);
- format(strInfo, sizeof(strInfo), "%s joined to us",
- PlayerName(playerid));
- SendClientMessage(playerid, COLOR_YELLOW,
- "Use /irc to open dialog window");
- for(new i, gmax = GetMaxPlayers(); i < gmax; i++)
- {
- if(!IsPlayerConnected(i))
- continue;
- if(playerInfo[i][ircChannel] == playerInfo[playerid][ircChannel])
- SendClientMessage(i, COLOR_ORANGE, strInfo);
- }
- return 1;
- }
- if(strlen(ircChannels[(listitem + 1)][pass]))
- {
- ShowPlayerDialog(playerid, IRC_CHANNEL_PASS2, DIALOG_STYLE_INPUT,
- "Password",
- "",
- "Join",
- "Cancel");
- playerInfo[playerid][ircJoin] = (listitem + 1);
- return 1;
- }
- }
- if(dialogid == IRC_CHANNEL_PASS2)
- {
- if(strcmp(ircChannels[playerInfo[playerid][ircJoin]][pass],
- inputtext, false) == 0 && strlen(inputtext))
- {
- playerInfo[playerid][ircChannel] = playerInfo[playerid][ircJoin];
- new strInfo[100];
- format(strInfo, sizeof(strInfo), "You joined to %s channel",
- ircChannels[playerInfo[playerid][ircChannel]][names]);
- SendClientMessage(playerid, COLOR_GREEN, strInfo);
- format(strInfo, sizeof(strInfo), "%s joined to us",
- PlayerName(playerid));
- SendClientMessage(playerid, COLOR_YELLOW,
- "Use /irc to open dialog window");
- playerInfo[playerid][ircJoin] = 0;
- for(new i, gmax = GetMaxPlayers(); i < gmax; i++)
- {
- if(!IsPlayerConnected(i))
- continue;
- if(playerInfo[i][ircChannel] == playerInfo[playerid][ircChannel])
- SendClientMessage(i, COLOR_ORANGE, strInfo);
- }
- return 1;
- }
- }
- if(dialogid == IRC_MESSAGE)
- {
- ShowPlayerDialog(playerid, IRC_MESSAGE_SEND, DIALOG_STYLE_INPUT,
- "Message",
- "",
- "Send",
- "Back");
- playerInfo[playerid][windowOpen] = false;
- return 1;
- }
- if(dialogid == IRC_MESSAGE_SEND)
- {
- if(strlen(inputtext) >= 40)
- {
- ShowPlayerDialog(playerid, IRC_MESSAGE_MSGBOX,
- DIALOG_STYLE_MSGBOX,
- "Error!",
- "Message is to long!",
- "Ok",
- "Close");
- return 1;
- }
- if(ircChannels[playerInfo[playerid][ircChannel]][message] == 19)
- ircChannels[playerInfo[playerid][ircChannel]][message] = 0;
- format(chatHistory[playerInfo[playerid][ircChannel]][0],
- MAX_MESSAGE_STRING,
- "%s: %s\n",
- PlayerName(playerid), inputtext);
- for(new i = 19; i >= 1; i--)
- {
- format(chatHistory[playerInfo[playerid][ircChannel]][i],
- MAX_MESSAGE_STRING,
- "%s",
- chatHistory[playerInfo[playerid][ircChannel]][i - 1]);
- }
- playerInfo[playerid][windowOpen] = true;
- new strTitle[45], strChat[2500];
- for(new i = 1; i < MAX_MESSAGE; i++)
- {
- if(!strlen(chatHistory[playerInfo[playerid][ircChannel]][i]))
- continue;
- strcat(strChat, chatHistory[playerInfo[playerid][ircChannel]][i],
- sizeof(strChat));
- }
- format(strTitle, sizeof(strTitle), "Channel #%s",
- ircChannels[playerInfo[playerid][ircChannel]][names]);
- for(new i, gmax = GetMaxPlayers(); i < gmax; i++)
- {
- if(!IsPlayerConnected(i))
- continue;
- if(playerInfo[i][ircChannel] == playerInfo[playerid][ircChannel])
- {
- if(i != playerid)
- GameTextForPlayer(i,
- "~g~New message on ~r~IRC channel",
- 1000,
- 5);
- if(playerInfo[i][windowOpen] == true)
- ShowPlayerDialog(i, IRC_MESSAGE, DIALOG_STYLE_LIST,
- strTitle,
- strChat,
- "Write",
- "Hide");
- }
- }
- }
- }
- if(response == 0)
- {
- if(dialogid == IRC_CHANNEL_NAME)
- {
- playerInfo[playerid][createChannel] = 0;
- return 1;
- }
- if(dialogid == IRC_CHANNEL_PASS)
- {
- new strInfo[45];
- format(strInfo, sizeof(strInfo), "Name: %s without password",
- ircChannels[playerInfo[playerid][createChannel]][names],
- ircChannels[playerInfo[playerid][createChannel]][pass]);
- SendClientMessage(playerid, COLOR_GREEN, strInfo);
- SendClientMessage(playerid, COLOR_YELLOW,
- "Use /irc to open dialog window");
- playerInfo[playerid][ircChannel] = playerInfo[playerid][createChannel];
- return 1;
- }
- if(dialogid == IRC_MESSAGE_SEND)
- {
- new strTitle[45], strChat[2500];
- format(strTitle, sizeof(strTitle), "Channel #%s",
- ircChannels[playerInfo[playerid][ircChannel]][names]);
- playerInfo[playerid][windowOpen] = true;
- for(new i = 1; i < MAX_MESSAGE; i++)
- {
- if(!strlen(chatHistory[playerInfo[playerid][ircChannel]][i]))
- continue;
- strcat(strChat, chatHistory[playerInfo[playerid][ircChannel]][i],
- sizeof(strChat));
- }
- if(!strlen(strChat))
- {
- ShowPlayerDialog(playerid, IRC_CHANNEL_JOIN, DIALOG_STYLE_LIST,
- strTitle,
- "No Message",
- "Write",
- "Hide");
- return 1;
- }
- ShowPlayerDialog(playerid, IRC_MESSAGE, DIALOG_STYLE_LIST, strTitle,
- strChat,
- "Wtite",
- "Hide");
- }
- if(dialogid == IRC_MESSAGE)
- playerInfo[playerid][windowOpen] = false;
- }
- return 1;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement