C++ Question Would Any one know?

Post Reply
WiiStream

C++ Question Would Any one know?

Post by WiiStream » Tue Feb 12, 2013 8:55 pm

I am trying to write a little addon for the core im using, and I have ran into a problem.
I am trying to get a string from the database. Heres what I got working so far.

Code: Select all

int32 count;
	int32 message_id;
	string_t message;
	string_t username;


	// char will not be logged in so get the id manually
	const int8* Query = "SELECT message_id, username, message FROM phpbb_chat WHERE count = '0';";
	int32 ret = Sql_Query(SqlHandle,Query);

	if (Sql_NextRow(SqlHandle) == SQL_SUCCESS)
	{
		
		
	
	message_id = (int32)Sql_GetIntData(SqlHandle,0);
	username = (int32) Sql_GetUIntData(SqlHandle,0);<______________________PROBLEM CAN NOT GET THE STRING
	message	= (int32) Sql_GetUIntData(SqlHandle,0);<______________________PROBLEM CAN NOT GET THE STRING
	count = (int32)Sql_GetIntData(SqlHandle,0);
ShowNotice(CL_RED"TRACER:COMMAND: CRecastContainer::Check MessageID %u Username %s Message %s Count %u \n" CL_RESET,message_id,username.c_str(),message.c_str(),count);	
	}


Print out loos like this.
TRACER:COMMAND: CRecastContainer::Check MessageID 470 Username NULL Message NULL Count 0

It should look lie this
TRACER:COMMAND: CRecastContainer::Check MessageID 470 Username Clarity Message Hello World Count 0

Now Message_ID and Count works it is pulling the correct data.
message_id = (int32)Sql_GetIntData(SqlHandle,0);<____________________________THIS IS GOOD
username = (int32) Sql_GetUIntData(SqlHandle,0);<______________________PROBLEM CAN NOT GET THE STRING
message = (int32) Sql_GetUIntData(SqlHandle,0);<______________________PROBLEM CAN NOT GET THE STRING
count = (int32)Sql_GetIntData(SqlHandle,0);<____________________________THIS IS GOOD


So it leads me to believe the problem is with
username = (int32) Sql_GetUIntData(SqlHandle,0);<______________________PROBLEM CAN NOT GET THE STRING
message = (int32) Sql_GetUIntData(SqlHandle,0);<______________________PROBLEM CAN NOT GET THE STRING

I thought there would be Sql_GetStrData like there is Sql_GetUIntData but there is not one.
Would anyone know the solution?

User avatar
kjLotus
Special Guest
Posts: 1813
Joined: Sun Jul 22, 2012 2:16 pm

Re: C++ Question Would Any one know?

Post by kjLotus » Tue Feb 12, 2013 9:29 pm

Sql_GetData

WiiStream

Re: C++ Question Would Any one know?

Post by WiiStream » Wed Feb 13, 2013 12:10 am

ya i was looking at that, and i tried it and it crashed.. Ill get back to it latter.

Heres what I added in the core for global chat

Code: Select all

else if (RBUFB(data,(0x06)) == '?')
	{
		
		 for (uint16 zone = 0; zone < 256; ++zone)
            {
            zoneutils::GetZone(zone)->PushPacket(
                NULL, 
                CHAR_INZONE, 
             new CChatMessagePacket(PChar,MESSAGE_SHOUT, data+7));
            }
		 const int8* fmtQuery;
		 if(PChar->nameflags.flags ==FLAG_GM)
		 {
			fmtQuery = "INSERT INTO phpbb_chat SET user_id ='2', username = '[GM] %s', user_colour ='AA0000', message = '%s', count = '1'";
		 }
		 else
		 {
            fmtQuery = "INSERT INTO phpbb_chat SET user_id ='2', username = '[Player] %s', user_colour ='AA0000', message = '%s', count = '1'";
		 }

			Sql_Query(SqlHandle,fmtQuery,PChar->name.c_str(),data+7);
			
		
	}
so it post on the website what were chating about in globle chat.
I didn't have any problems here.

and then in the packet update section I added this code to receive the message back in to the client but I can not get it working yet..
I also what to slow it down so its not selecting from the database every second. I would like to wait at least 10 seconds to do the check!
I also have to add bufsize of getting only 119 chars per message received!

Code: Select all

int32 message_id;
	string_t message ="Is requesting some one to respond.";<_______________TEMP SHOULD BE THE POSTERS MESSAGE
	string_t username = "Guest";<_______________TEMP SHOULD BE THE POSTERS NAME


	// char will not be logged in so get the id manually
	const int8* Query = "SELECT message_id, username, message FROM phpbb_chat WHERE count = '0';";
	int32 ret = Sql_Query(SqlHandle,Query);

	if (ret != SQL_ERROR && Sql_NumRows(SqlHandle) != 0 && Sql_NextRow(SqlHandle) == SQL_SUCCESS)
	{
		
		
	
	message_id = (int32)Sql_GetIntData(SqlHandle,0);
	//username =  Sql_GetData(SqlHandle,1);
	//message	=  Sql_GetData(SqlHandle,2);
	
	

	 char buf[110];
	 sprintf(buf,"[Web Chat] %s %s",username.c_str(), message.c_str());
	for (uint16 zone = 0; zone < 256; ++zone)
            {
            zoneutils::GetZone(zone)->PushPacket(
                NULL, 
                CHAR_INZONE, 
             new CChatMessageStringPacket(PChar, MESSAGE_STRING_SAY , ("%s",buf)));
            }

       Query = "UPDATE phpbb_chat SET count = '1' WHERE message_id = %u;";

	Sql_Query(SqlHandle, Query,message_id);
        
	    
	ShowNotice(CL_RED"TRACER:COMMAND: CRecastContainer::Check MessageID %u Username %s Message %s  \n" CL_RESET,message_id,username.c_str(),message.c_str());	
	}
heres a demo of it http://www.wiistream.com/forums/index.php

User avatar
kjLotus
Special Guest
Posts: 1813
Joined: Sun Jul 22, 2012 2:16 pm

Re: C++ Question Would Any one know?

Post by kjLotus » Wed Feb 13, 2013 12:55 am

seems kinda cool

WiiStream

Re: C++ Question Would Any one know?

Post by WiiStream » Fri Feb 15, 2013 12:30 am

How would I go about placing a limit on the incoming chat?

I'm not too good with C++ yet, but i was thinking something like this.

if(buf =<110)
{
DO SCRIPT.
}

i think that says if buf = less then 100 chars do script..

That's the code I need how can I do that? would anyone be able to help me with that.

Post Reply