Raised This Month: $32 Target: $400
 8% 

[REQ] CS:GO Cross Server Chat


Post New Thread Reply   
 
Thread Tools Display Modes
Potato Uno
Veteran Member
Join Date: Jan 2014
Location: Atlanta, Georgia
Old 08-11-2015 , 02:56   Re: [REQ] CS:GO Cross Server Chat
Reply With Quote #11

Use SQL_TQuery to execute a query and pass in a function that will get called once the query completes.
Potato Uno is offline
derptestt
Senior Member
Join Date: Jul 2015
Old 08-11-2015 , 03:24   Re: [REQ] CS:GO Cross Server Chat
Reply With Quote #12

I just copied what I thought looked useful from the kztimer sql.sp, and modified it. I apologize in advance if this is just a complete failed code. But would this at least create a table called Chat and insert the chat string into it?

PHP Code:
new String:sql_createChat[]
new 
String:sql_insertChat[]

public 
db_setupDatabase()
{
    
decl String:szError[255];
    
g_hDb SQL_Connect("serverchat"falseszError255);
        
    if(
g_hDb == INVALID_HANDLE)
    {
        
SetFailState("[Server Chat] Unable to connect to database (%s)",szError);
        return;
    }
        
    
decl String:szIdent[8];
    
SQL_ReadDriver(g_hDbszIdent8);
        
    if(
strcmp(szIdent"mysql"false) == 0)
    {
        
g_DbType MYSQL;
    }
    else 
        if(
strcmp(szIdent"sqlite"false) == 0)
            
g_DbType SQLITE;
        else
        {
            
LogError("[Server Chat] Invalid Database-Type");
            return;
        }
        
    
SQL_FastQuery(g_hDb,"SET NAMES  'utf8'");
    
db_createTables();
}

public 
db_createTables()
{
    
SQL_LockDatabase(g_hDb);     
    
SQL_FastQuery(g_hDbsql_createChat);
    
SQL_UnlockDatabase(g_hDb);
}

public 
db_InsertChat(String:szChatText[4096])
{
    
decl String:szQuery[512];       
    
Format(szQuery512sql_insertChatszChatText); 
    
SQL_TQuery(g_hDbSQL_CheckCallbackszQuery,DBPrio_Low);


Last edited by derptestt; 08-11-2015 at 03:25.
derptestt is offline
m_bNightstalker
Senior Member
Join Date: Jan 2015
Location: JWD
Old 08-11-2015 , 04:06   Re: [REQ] CS:GO Cross Server Chat
Reply With Quote #13

Init:
Code:
CREATE TABLE IF NOT EXISTS `xchat` (`id` int(11) NOT NULL AUTO_INCREMENT, `server` int(11) NOT NULL, `msg` varchar(2048) NOT NULL, PRIMARY KEY (`id`));

FormatEx(query, sizeof(query), "SELECT `id` FROM `xchat` WHERE `server` != %d;", g_iServerID);

while (SQL_FetchRow(hndl))
{
    new id  = SQL_FetchInt(hndl, 0);

    if(id > g_iLastID)
        g_iLastID = id;
}
Push chat message:
Code:
FormatEx(query, sizeof(query), "INSERT INTO `xchat` (msg, server) VALUES ('%s','%d');", sText, g_iServerID);
Read new chat messages:
Code:
FormatEx(query, sizeof(query), "SELECT `id`, `msg` FROM `xchat` WHERE `server` != %d AND `id` > '%d';", g_iServerID, g_iLastID);

while (SQL_FetchRow(hndl))
{
    id = SQL_FetchInt(hndl, 0);
    SQL_FetchString(hndl, 1, text, sizeof(text));

    if(id > g_iLastID)
    {
        g_iLastID = id;
        CPrintToChatAll(text);
    }
}
m_bNightstalker is offline
derptestt
Senior Member
Join Date: Jul 2015
Old 08-11-2015 , 04:12   Re: [REQ] CS:GO Cross Server Chat
Reply With Quote #14

m_bNightstalker: Can I add you on Steam to discuss this?
derptestt is offline
m_bNightstalker
Senior Member
Join Date: Jan 2015
Location: JWD
Old 08-11-2015 , 04:52   Re: [REQ] CS:GO Cross Server Chat
Reply With Quote #15

Quote:
Originally Posted by derptestt View Post
m_bNightstalker: Can I add you on Steam to discuss this?
I'm not your personal sourcepawn teacher, sry. Everyone who can code a bit can write this plugin with the given help.
m_bNightstalker is offline
derptestt
Senior Member
Join Date: Jul 2015
Old 08-11-2015 , 05:08   Re: [REQ] CS:GO Cross Server Chat
Reply With Quote #16

Quote:
Originally Posted by m_bNightstalker View Post
I'm not your personal sourcepawn teacher, sry. Everyone who can code a bit can write this plugin with the given help.
It's cool, I'll just study the API and some basic programming logic for a few months and then come back to this. Thank you for the code though, my friend says it makes sense.

Btw I was going to offer you BitCoins.

Last edited by derptestt; 08-11-2015 at 05:15.
derptestt is offline
ecca
Sexy Santa
Join Date: Jan 2011
Old 08-11-2015 , 09:07   Re: [REQ] CS:GO Cross Server Chat
Reply With Quote #17

Why not either write a php code that pushes message to all servers at once or use a middleman such as nodejs to read and push messages. You could also do with MySQL, but it all depend on preferences.
__________________
ecca is offline
derptestt
Senior Member
Join Date: Jul 2015
Old 08-11-2015 , 14:28   Re: [REQ] CS:GO Cross Server Chat
Reply With Quote #18

I'm going to spew out some intense logic here. I wouldn't have posted in the REQUEST section of the forum, if I already knew how to do it. It goes on my understanding as I don't mess with PHP or SourcePawn on that level. I understand if people don't want to do it for me or share their code. If you know how though, and you just want a few bucks to do it, I'm willing. Thank you.
derptestt is offline
shavit
AlliedModders Donor
Join Date: Dec 2011
Location: Israel
Old 08-11-2015 , 16:22   Re: [REQ] CS:GO Cross Server Chat
Reply With Quote #19

Quote:
Originally Posted by derptestt View Post
I know this is a lot to ask, but do y'all know a plugin that utilizes SQL, so I can take a peek at how it works within SourcePawn? Right now I'm looking at the sql.sp included in the KZTimer mod, but it's a bit overwhelming. Thank you in advance.
I'm doing some SQL stuff here; https://github.com/Shavitush/bhoptim...ster/scripting
__________________
retired
shavit is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 08-11-2015 , 20:34   Re: [REQ] CS:GO Cross Server Chat
Reply With Quote #20

socket is way better. Your mysql server is going to get raped doing that many queries, moreso if you have lots of servers.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 04:47.


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