AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Reliable CHannel Overflow (https://forums.alliedmods.net/showthread.php?t=56777)

Rolnaaba 06-20-2007 18:44

Reliable CHannel Overflow
 
I made this simple plugin for my clan's server so that we could advertise new ect. It works perfectly, but it causes a reliable channel overflow error eventually. we had msg_delay set to 90.0 and 60.0seconds the times this happened any ideas?
Code:
#include <amxmodx> #include <amxmisc> new msg_file[128]; new ReadData[512]; new MsgSayText; public plugin_init() {     register_plugin("Message Display", "1.0", "Rolnaaba");         register_cvar("msg_delay", "120.0"); //how long between each message (seconds)         set_task(get_cvar_float("msg_delay"), "load_message");     MsgSayText = get_user_msgid("SayText"); } public load_message() {     get_configsdir(msg_file, 127);     formatex(msg_file, 127, "%s/message.ini", msg_file);                 new file = fopen(msg_file, "r");               if(file) {                   while(!feof(file)) {             fgets(file, ReadData, 511);                         if(ReadData[0] == ';')                 continue;                             display_message(ReadData);         }         fclose(file);     } else {         log_amx("Unable to find message.ini, Plugin Failed. Please place message.ini into your configs folder!");                 set_fail_state("Unable to find message.ini, Plugin Failed. Please place message.ini into your configs folder!");     } } public display_message(message[]) {     new message2[536];     formatex(message2, 535, "^x04%s", message);         new players[32], num, i;     get_players(players, num);     for(i = 0; i <= num; i++) {         new y = players[i];         if(!is_user_connected(y) || is_user_bot(y)) continue;         message_begin(MSG_ONE, MsgSayText, {0,0,0}, y);         write_byte(y);         write_string(message2);         message_end();     }         set_task(get_cvar_float("msg_delay"), "load_message"); }

_Master_ 06-20-2007 18:51

Re: Reliable CHannel Overflow
 
1. Why don't you set a looping task for it ?
2. Take a closer look at your while() loop...

Alka 06-20-2007 18:51

Re: Reliable CHannel Overflow
 
I think is because you send this to many players in the same moment!Why you don't send the message to all players by "0" with "client_print" ?

Rolnaaba 06-20-2007 18:56

Re: Reliable CHannel Overflow
 
client print doesnt support the ^x04 color thing, and thats the only way I know how to make it colored green, is there a way to color it green with client print?

pRED* 06-20-2007 20:38

Re: Reliable CHannel Overflow
 
Do it the same way you're doing it but change from MSG_ONE (message sent to a single client, over reliable data stream) to MSG_BROADCAST (message to all players, unreliable).

This removes the need for a loop and MSG_BROADCAST is the equivalent of client_print(0...) and also it's unreliable which means (i think) it doesn't get sent if its going to cause an overflow.

Also you don't need to read the file in every time you want to display the message. Read the file once on map load into a string array (define a number like MAX_ADS 30, new ads[MAX_ADS][128])

Then just loop through that array when you want to print..

Rolnaaba 06-20-2007 22:00

Re: Reliable CHannel Overflow
 
thnx
Code:
message_begin(MSG_BROADCAST, MsgSayText);     write_byte(0);     write_string(message2);     message_end();
like that?

Alka 06-21-2007 03:34

Re: Reliable CHannel Overflow
 
Quote:

Originally Posted by Rolnaaba (Post 492551)
client print doesnt support the ^x04 color thing, and thats the only way I know how to make it colored green, is there a way to color it green with client print?

Like this? Messages in chat . http://forums.alliedmods.net/showthread.php?t=45753

_Master_ 06-21-2007 05:10

Re: Reliable CHannel Overflow
 
Turning this to MSG_BROADCAST is only a workaround to the problem. It will still flood the channel.

Again, your while() loop is causing this.

Rolnaaba 06-21-2007 07:35

Re: Reliable CHannel Overflow
 
well how can I do it differently Master?
updated code:
Code:
#include <amxmodx> #include <amxmisc> #define MAXLINES 11 new msg_file[128]; new ReadData[512]; new MsgSayText; new ads[MAXLINES][256] new atline = 0; public plugin_init() {     register_plugin("Message Display", "1.0", "Rolnaaba");         register_cvar("msg_delay", "120.0"); //how long between each message (seconds)         MsgSayText = get_user_msgid("SayText");         load_message();         set_task(get_cvar_float("msg_delay"), "display_message"); } public load_message() {     get_configsdir(msg_file, 127);     formatex(msg_file, 127, "%s/message.ini", msg_file);                 new file = fopen(msg_file, "r");               if(file) {                   while(!feof(file)) {             fgets(file, ReadData, 511);                         if(ReadData[0] == ';')                 continue;             if(atline >= MAXLINES) {                 log_amx("Message too long, cutting it off atline = %i", atline);                 continue;             }                             copy(ads[atline], 511, ReadData);             atline++;         }         fclose(file);                 for(new i; i <= atline; i++) {             formatex(ads[i], 255, "^x04%s", ads[i]);         }     } else {         log_amx("Unable to find message.ini, Plugin Failed. Please place message.ini into your configs folder!");                 set_fail_state("Unable to find message.ini, Plugin Failed. Please place message.ini into your configs folder!");     } } public display_message() {     new players[32], num;     get_players(players, num);         for(new i; i <= atline; i++) {         message_begin(MSG_BROADCAST, MsgSayText);         write_byte(0);         write_string(ads[i]);         message_end();     }         set_task(get_cvar_float("msg_delay"), "load_message"); }

Rolnaaba 07-04-2007 22:47

Re: Reliable CHannel Overflow
 
ok, I found a different way to do it, but I dont know if it will work, and I dont have anyway to test it right now. Can anyone spot anyhting bad, or can test this for me or anything.

Here is my new way. I stole loading from superhero, so it has a different while() loop.

Code:
#include <amxmodx> #include <amxmisc> #define MAXLINES 11 new file[128]; new readLine = 0; new lengthRead; new data[1024]; new MsgSayText; new ads[MAXLINES][192] new total_lines; public plugin_init() {     register_plugin("Message Display", "1.0", "Rolnaaba");         register_cvar("msg_delay", "120.0"); //how long between each message (seconds)         MsgSayText = get_user_msgid("SayText");         load_message();         set_task(get_cvar_float("msg_delay"), "display_message", 0, "", 0, "b"); } public load_message() {     get_configsdir(file, 127);     formatex(file, 127, "%s/message.ini", file);                 if(!file_exists(file)) {         log_amx("Unable to find message.ini, Plugin Failed. Please place message.ini into your configs folder!");                 set_fail_state("Unable to find message.ini, Plugin Failed. Please place message.ini into your configs folder!");     }     while((readLine = read_file(file, readLine, data, 1023, lengthRead)) != 0) {         if(equal(data[0], ";")) continue;         data[191] = '^0'         copy(ads[readLine], 191, data);                 total_lines++;     } } public display_message() {     new players[32], num;     get_players(players, num);         for(new i; i <= total_lines; i++) {         message_begin(MSG_BROADCAST, MsgSayText);         write_byte(0);         write_string(ads[i]);         message_end();     } }


All times are GMT -4. The time now is 21:24.

Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.