You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
2.5 KiB
78 lines
2.5 KiB
#include <sourcemod>
|
|
|
|
char g_MessageChatPrefix[16] = "[FSB.Message]";
|
|
char g_MessageTableName[32] = "user_messages";
|
|
|
|
char g_SQL_QUERY_ADDMESSAGE[512] = "INSERT INTO `%s` (`account_id`, `utime`, `message`, `server_id`) VALUES ('%d', '%d', '%s', '%s')";
|
|
|
|
Handle g_hMessageDatabase = INVALID_HANDLE;
|
|
char g_messages_server_id[32] = "";
|
|
|
|
stock messagesSetServerId(const char[] server_id, int size) {
|
|
strcopy(g_messages_server_id, size, server_id);
|
|
PrintToServer("%s server id is setted: %s", g_MessageChatPrefix, g_messages_server_id)
|
|
}
|
|
|
|
stock MessageSetup(){
|
|
RegConsoleCmd("say", SayHook);
|
|
RegConsoleCmd("say_team", SayHook);
|
|
}
|
|
|
|
|
|
stock bool MessageTable_VerifyTable(const char[] database_name, const char[] table_name){
|
|
char error[255], query[2048];
|
|
new db = SQL_Connect(database_name, true, error, sizeof(error));
|
|
if (db == INVALID_HANDLE) {
|
|
LogError("%s Cannot connect to Database: %s", g_MessageChatPrefix, database_name);
|
|
return false;
|
|
}
|
|
|
|
Format(query, sizeof(query), "%s%s%s%s%s%s%s%s",
|
|
"CREATE TABLE IF NOT EXISTS `",
|
|
g_MessageTableName,
|
|
"`id` int(11) NOT NULL,"
|
|
"`account_id` int(11) NOT NULL,"
|
|
"`utime` bigint(20) NOT NULL,"
|
|
"`message` varchar(512) NOT NULL,"
|
|
"`server_id` varchar(32) NOT NULL"
|
|
") ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;");
|
|
|
|
bool success = SQL_FastQuery(db, query);
|
|
if(!success) {
|
|
SQL_GetError(db, error, sizeof(error));
|
|
LogError("%s [ERROR] Unable to verify %s table:%s", g_MessageChatPrefix, g_MessageTableName, query);
|
|
LogError("%s [ERROR] %s", g_MessageChatPrefix, error);
|
|
}
|
|
|
|
CloseHandle(db);
|
|
return true;
|
|
}
|
|
|
|
stock void AddMessage(int account_id, const String:message[]) {
|
|
char Query[512];
|
|
char EscMessage[256];
|
|
SQL_EscapeString(g_hMessageDatabase, message, EscMessage, sizeof(EscMessage));
|
|
Format(Query, sizeof(Query), g_SQL_QUERY_ADDMESSAGE, g_MessageTableName, account_id, GetTime(), EscMessage, g_messages_server_id);
|
|
SQL_TQuery(g_hMessageDatabase, CallBack_AddMessage, Query, 0);
|
|
}
|
|
|
|
public CallBack_AddMessage(Handle:owner, Handle:hndl, const String:error[], any:data) {
|
|
if (hndl == INVALID_HANDLE) {
|
|
LogError("%s Query failed! %s", g_MessageChatPrefix, error);
|
|
return;
|
|
}
|
|
}
|
|
|
|
public Action SayHook(int cid, int args){
|
|
char message[256];
|
|
GetCmdArgString(message, sizeof(message));
|
|
StripQuotes(message);
|
|
|
|
if (message[1] == '!' || message[0] == '!'){//1 потому что ебаные " при вызове GetCmdArgString
|
|
return Plugin_Continue;
|
|
}
|
|
|
|
int account_id = GetSteamAccountID(cid, true);
|
|
AddMessage(account_id, message);
|
|
return Plugin_Continue;
|
|
}
|