[SRC] Notice.txt fix

Codes already submitted by people of the forums.
Dax
<3 bd long time
Posts: 785
Joined: Mon Apr 18, 2005 3:19 pm

Post by Dax »

Code purpose: Display a random message from a file every 3min to every connected player.
Image

<!--QuoteBegin-notice.txt+--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td>QUOTE (notice.txt)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin-->notice_message_1
notice_message_2
notice_message_3
notice_message_4
notice_message_5
dax's_pee_pee_is_bigger_then_yours[/quote]
Notes:
- 1 Message from notice.txt is sent to every player online every 3 minutes.
- Any underscore("_") in the message will be displayed as a space.
- All messages must be 1 line. (Seperate words with "_")
- The new message displayed will never be the same as the previous.
- notice.txt is placed in the same location as HGServer.exe

Anyone who has ran a server knows about that notice.txt. Always there to give you an error and if you added it then it didnt do shit beyond that. Well i was reading the code and noticed it was to announce messages to clients from a list of messages inside the txt.

Well it looked like it was only decoding 1 word as it's message. The code was all over the place and actual timer they used was like 2 timers in 1. Messy as hell code. Anyway i fucked around with it for a few minutes and basically rewrote the loading and syntax of the file.

HGServer->Game.cpp->Replace bReadNotifyMsgListFile

Code: Select all

BOOL CGame::bReadNotifyMsgListFile(char * cFn)
{
 FILE * pFile;
 HANDLE hFile;
 DWORD  dwFileSize;
 char * cp, * token;
 char seps[] = "=\t\n;";
 class CStrTok * pStrTok;
 int   i;
 BOOL bRead;

	bRead = FALSE;
	m_iTotalNoticeMsg = 0;
	hFile = CreateFile(cFn, GENERIC_READ, NULL, NULL, OPEN_EXISTING, NULL, NULL);
	dwFileSize = GetFileSize(hFile, NULL);
	if (hFile != INVALID_HANDLE_VALUE) CloseHandle(hFile);
	pFile = fopen(cFn, "rt");
	if (pFile == NULL) {
  PutLogList("(!) Notify Message list file not found!...");
  return FALSE;
	}
	else 
	{
  PutLogList("(!) Reading Notify Message list file...");
  cp = new char[dwFileSize+2];
  ZeroMemory(cp, dwFileSize+2);
  fread(cp, dwFileSize, 1, pFile);

  pStrTok = new class CStrTok(cp, seps);
  token = pStrTok->pGet();
  while( token != NULL )   
  {
  	for (i = 0; i < 1000; i++) if (token[i] == '_') token[i] = ' ';
  	PutLogList(token);
  	if (m_iTotalNoticeMsg < DEF_MAXNOTIFYMSGS) 
  	{
    if (m_pNoticeMsgList[m_iTotalNoticeMsg] == NULL) 
    	m_pNoticeMsgList[m_iTotalNoticeMsg] = new class CMsg;	
    	m_pNoticeMsgList[m_iTotalNoticeMsg]->bPut(NULL, token, strlen(token), NULL, NULL);
    	m_iTotalNoticeMsg++;
  	}
  	token = pStrTok->pGet();
  }
  delete pStrTok;
  delete cp;
	}
	if (pFile != NULL) fclose(pFile);

	return TRUE;
}
HGServer->Game.cpp->Replace NoticeHandler()

Code: Select all

void CGame::NoticeHandler()
{
 char  cTemp, cBuffer[1000], cKey;
 DWORD dwSize, dwTime = timeGetTime();
 register int i, iMsgIndex, iTemp;

	if (m_iTotalNoticeMsg <= 1) return;

  do {
  	iMsgIndex = iDice(1, m_iTotalNoticeMsg) - 1;
  } while (iMsgIndex == m_iPrevSendNoticeMsg);

  m_iPrevSendNoticeMsg = iMsgIndex;
  
  ZeroMemory(cBuffer, sizeof(cBuffer));
  if (m_pNoticeMsgList[iMsgIndex] != NULL) 
  {
  	m_pNoticeMsgList[iMsgIndex]->Get(&cTemp, cBuffer, &dwSize, &iTemp, &cKey);
  }
  
  for (i = 1; i < DEF_MAXCLIENTS; i++)
  if (m_pClientList[i] != NULL) 
  {
  	SendNotifyMsg(NULL, i, DEF_NOTIFY_NOTICEMSG, NULL, NULL, NULL, cBuffer);
  }
}
Now we gotta change where NoticeHandler() is called from. STech originaly had this in a timer calling every 3 seconds, then had another timer inside the handler to go off at a later time(can't remember how long). Anyway it sucked.

In the function OnTimer(char cType) find UpdateHandler(); and delete it. In the same function find if ((dwTime - m_dwGameTime5) > 1000*60*3) {. After that code put UpdateHandler();

Now the server calls UpdateHandler() every 3 minutes to send a new message to every connected player.

Functions:
bReadNotifyMsgListFile(char * cFn) - Reads the file notice.txt. Each line is read as a notice message. The character "_" is replaced with a space when the file is being read.

UpdateHandler() - Randomly selects a message from the notice messages list. If the message is the same as the previous displayed message then it will select a new message. When the function has found a new message it will send the message to every connected client.

[EDIT] There will be some variables left over which my codes don't use. They will cause warnings. If you don't know how to remove them then just leave them. You deserve them. Plus they won't harm you.
Reppin' 127.0.0.1!!!<br><br><img src='http://img502.imageshack.us/img502/1348/sig4daxbn2.jpg' border='0' alt='user posted image' /><br><br>I contend that we are both atheists. I just believe in one fewer god than you do. <br>When you understand why you dismiss all the other possible gods, you will <br>understand why I dismiss yours.<br>~ <b>Stephen Roberts</b>
ADDKiD
&lt;3 bd long time
Posts: 967
Joined: Tue Jul 12, 2005 8:07 pm
Location: Washington, USA
Contact:

Post by ADDKiD »

Sweet! Thanks Dax! I'll add it asap! You wanna release some Anti-Hack stuff now? :D
juggalo2
Spamtastic
Posts: 1144
Joined: Sun Jul 17, 2005 5:28 pm

Post by juggalo2 »

ADDKiD wrote: Sweet! Thanks Dax! I'll add it asap! You wanna release some Anti-Hack stuff now? :D
lol ahahah u aklways want ur shiot give to u u cant code u nver realse shit so stfu
<img src='http://lifeplaysu420.com/unknow/nightsign.png' border='0' alt='user posted image' /><br>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~<br>Wanna make money for surfing the net sing up at <br><a href='http://www.cashfiesta.com/php/join.php? ... yprivitera' target='_blank'>cash fiesta</a><br>its all free hey why ntot make money while fucking around on the computer<br><br><br>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Dax
&lt;3 bd long time
Posts: 785
Joined: Mon Apr 18, 2005 3:19 pm

Post by Dax »

juggalo2 wrote:
ADDKiD wrote: Sweet! Thanks Dax! I'll add it asap! You wanna release some Anti-Hack stuff now? :D
lol ahahah u aklways want ur shiot give to u u cant code u nver realse shit so stfu
And your comment regarding this topic is?
Reppin' 127.0.0.1!!!<br><br><img src='http://img502.imageshack.us/img502/1348/sig4daxbn2.jpg' border='0' alt='user posted image' /><br><br>I contend that we are both atheists. I just believe in one fewer god than you do. <br>When you understand why you dismiss all the other possible gods, you will <br>understand why I dismiss yours.<br>~ <b>Stephen Roberts</b>
1+12
Member
Posts: 173
Joined: Sat Feb 04, 2006 5:05 pm

Post by 1+12 »

juggalo2 wrote:
ADDKiD wrote: Sweet! Thanks Dax! I'll add it asap! You wanna release some Anti-Hack stuff now? :D
lol ahahah u aklways want ur shiot give to u u cant code u nver realse shit so stfu
No offense to juggalo

Just hard to read so I wrote it again for you

What Juggalo meant to say was

lol ahahah you always want your shit given to you , you cant code , you never release shit, so stfu.

But yeah Very nice code fix Dax :D
ADDKiD
&lt;3 bd long time
Posts: 967
Joined: Tue Jul 12, 2005 8:07 pm
Location: Washington, USA
Contact:

Post by ADDKiD »

Lol... Your right Juggalo2, I can't. But I am trying, I am trying to learn something that others say fuck it too... Instead of be littling me and giving me shit, why don't you try and help? Or is that too difficult for your puny mind to comprehend..?


Dax: Props for fixing this man. ^^
Dax
&lt;3 bd long time
Posts: 785
Joined: Mon Apr 18, 2005 3:19 pm

Post by Dax »

Holy shit. Forgot the whole reason i started this topic. I was gonna throw in a plug for a hoster. Oh well better late then never.

Anyone wanna host my files? They pwn shit good...
Reppin' 127.0.0.1!!!<br><br><img src='http://img502.imageshack.us/img502/1348/sig4daxbn2.jpg' border='0' alt='user posted image' /><br><br>I contend that we are both atheists. I just believe in one fewer god than you do. <br>When you understand why you dismiss all the other possible gods, you will <br>understand why I dismiss yours.<br>~ <b>Stephen Roberts</b>
bone-you
Spamtastic
Posts: 1310
Joined: Wed Mar 16, 2005 3:12 am

Post by bone-you »

ADDKiD wrote: Sweet! Thanks Dax! I'll add it asap! You wanna release some Anti-Hack stuff now? :D
Back to my other topic, again asking for shit xD leeching :P
<img src='http://www.helbreathx.net/sig/sig.jpeg' border='0' alt='user posted image' /><br><a href='http://mafia.cheats4us.org/index.php?x=231030' target='_blank'>#1 on Mafia :D</a><br><!--QuoteBegin-Slipknight+--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Slipknight)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin-->100mb Internet, burstable too 10GB oc192<br>his speed can go up too 10gbs<br>...<br>Yes my car can have a top speed of 1000mph<!--QuoteEnd--></td></tr></table><div class='signature'><!--QuoteEEnd--><br>^^ I wonder where the retard went to.
1+12
Member
Posts: 173
Joined: Sat Feb 04, 2006 5:05 pm

Post by 1+12 »

bone-you wrote:
ADDKiD wrote: Sweet! Thanks Dax! I'll add it asap! You wanna release some Anti-Hack stuff now? :D
Back to my other topic, again asking for shit xD leeching :P
Lol Zero
:P :P
bone-you
Spamtastic
Posts: 1310
Joined: Wed Mar 16, 2005 3:12 am

Post by bone-you »

1 wrote:
bone-you wrote:
ADDKiD wrote: Sweet! Thanks Dax! I'll add it asap! You wanna release some Anti-Hack stuff now? :D
Back to my other topic, again asking for shit xD leeching :P
Lol Zero
:P :P
Well shit. The retard is starting to do it on my forum too.
<img src='http://www.helbreathx.net/sig/sig.jpeg' border='0' alt='user posted image' /><br><a href='http://mafia.cheats4us.org/index.php?x=231030' target='_blank'>#1 on Mafia :D</a><br><!--QuoteBegin-Slipknight+--></div><table border='0' align='center' width='95%' cellpadding='3' cellspacing='1'><tr><td><b>QUOTE</b> (Slipknight)</td></tr><tr><td id='QUOTE'><!--QuoteEBegin-->100mb Internet, burstable too 10GB oc192<br>his speed can go up too 10gbs<br>...<br>Yes my car can have a top speed of 1000mph<!--QuoteEnd--></td></tr></table><div class='signature'><!--QuoteEEnd--><br>^^ I wonder where the retard went to.
Dax
&lt;3 bd long time
Posts: 785
Joined: Mon Apr 18, 2005 3:19 pm

Post by Dax »

bone-you wrote:
1 wrote:
bone-you wrote: Back to my other topic, again asking for shit xD leeching :P
Lol Zero
:P :P
Well shit. The retard is starting to do it on my forum too.
Oh fuck you cunts.. How about we leave going off-topic in dax's topics to dax? Pricks!

Now who the fuck wants to host my files? :D
Reppin' 127.0.0.1!!!<br><br><img src='http://img502.imageshack.us/img502/1348/sig4daxbn2.jpg' border='0' alt='user posted image' /><br><br>I contend that we are both atheists. I just believe in one fewer god than you do. <br>When you understand why you dismiss all the other possible gods, you will <br>understand why I dismiss yours.<br>~ <b>Stephen Roberts</b>
Kenshi
Loyal fan
Posts: 208
Joined: Thu Nov 20, 2003 8:27 am

Post by Kenshi »

dax ya bitch gimme ya files are they any good whats good about them lol
get rooted.
Dax
&lt;3 bd long time
Posts: 785
Joined: Mon Apr 18, 2005 3:19 pm

Post by Dax »

Kenshi wrote: dax ya bitch gimme ya files are they any good whats good about them lol
No bugs at all(that i can see)... Some shit is missing from 2.20->3.82 like some NPC, Items and spells. But once i get it up and work out exactly what is missing i'll fix that shit in a day at most. Plus i'll fix any other dead features i find like i've already been doing. I've fixed a lot of stuff stech couldnt even fix. Like remembering the attack mode. That is sweet. Switch any map logout die and your attack mode stays the same(Good for pvp). And yer heaps more secret shit which i havnt released here, plus, no bugs!.

[EDIT] and a tonne of tweaks over stech's crap. i tweak anything if i skim over it and it looks shit.
Reppin' 127.0.0.1!!!<br><br><img src='http://img502.imageshack.us/img502/1348/sig4daxbn2.jpg' border='0' alt='user posted image' /><br><br>I contend that we are both atheists. I just believe in one fewer god than you do. <br>When you understand why you dismiss all the other possible gods, you will <br>understand why I dismiss yours.<br>~ <b>Stephen Roberts</b>
Crossfade
Loyal fan
Posts: 354
Joined: Sun Mar 20, 2005 5:55 pm

Post by Crossfade »

I'd host it for you Dax, but I don't have a computer for hosting purposes at most and no time, but I do have the knowledge lol.
ADDKiD
&lt;3 bd long time
Posts: 967
Joined: Tue Jul 12, 2005 8:07 pm
Location: Washington, USA
Contact:

Post by ADDKiD »

Dax, you really ought to do is fix the router problem. I'll host. I'm fixing my Computer area now. I built some things in metal shop to soften my Computers noise. =) I'll be able to host 24/7 soon.
Post Reply