Author Topic: ULX Chat (UChat) SQL Database  (Read 6600 times)

0 Members and 1 Guest are viewing this topic.

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
ULX Chat (UChat) SQL Database
« on: January 04, 2012, 08:22:18 PM »
This is just a suggestion (That's why I'm here), but I believe that someone with the skills of lua and ulx should create a multichat command for two or more servers. The reason that ulx would be involved in this is cause (ulx is great and the best) [Look at Picture].

Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: ULX Chat (UChat) SQL Database
« Reply #1 on: January 05, 2012, 10:25:48 AM »
Also I didn't say this before but it would be in a SQL database (Not Lite)
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline Megiddo

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 6214
  • Karma: 394
  • Project Lead
Re: ULX Chat (UChat) SQL Database
« Reply #2 on: January 05, 2012, 12:15:13 PM »
SQL is not a good platform for implementing a near real-time chat system. SQL is meant to store information, not pass it along. Yes, this is technically feasible, but it's much better implemented properly using sockets.

That aside, nice UI mockup for such a system. I don't currently have time to work on something like this, but maybe someone would be willing to pick it up. :)
Experiencing God's grace one day at a time.

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: ULX Chat (UChat) SQL Database
« Reply #3 on: January 05, 2012, 12:38:03 PM »
That aside, nice UI mockup for such a system. I don't currently have time to work on something like this, but maybe someone would be willing to pick it up. :)

I actually used my good friend [evo]Lead4u APromote's menu. Which I made in MS Paint...
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: ULX Chat (UChat) SQL Database
« Reply #4 on: February 02, 2012, 05:51:10 PM »
I decided to change the name of it from UChat to mChat
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline MrPresident

  • Ulysses Team Member
  • Hero Member
  • *****
  • Posts: 2728
  • Karma: 430
    • |G4P| Gman4President
Re: ULX Chat (UChat) SQL Database
« Reply #5 on: February 04, 2012, 04:58:09 AM »
In case you aren't familiar with the tech behind Meg's statement, let me elaborate a little bit...

The only way for a chat system using SQL would be for the server to query the database at a set interval. This would create a (as near as you are willing to go) real time chat system between 2 or more servers, but the faster the queries the more chance of lagging the game server and so on.. also it's never going to be real time... feasibly you could do 30 seconds but any shorter would be unwise.. and who wants to wait 30 seconds or longer for messages to be received by another party.. this would create for an awkwardly long paused conversation..


Sockets on the other hand open up a port on the listening server and send data in real time to the listening ports. You could communicate between 2 servers using sockets or if someone were REALLY smart on it, you could create a simple socket server with .net or C++ which 2 or MORE servers could connect to and communicate in real time.


^^Why is it that I get the best ideas for things like this when I'm deployed and don't have the means to do them!!!

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: ULX Chat (UChat) SQL Database
« Reply #6 on: March 22, 2012, 08:36:02 PM »
Okay, Thank you for clearing that up. Sorry I don't really know Lua that well.
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.

Offline Bite That Apple

  • Hero Member
  • *****
  • Posts: 858
  • Karma: 416
  • Apple Innovations 2010®
    • Fun 4 Everyone Gaming
Re: ULX Chat (UChat) SQL Database
« Reply #7 on: June 29, 2012, 10:42:49 PM »
I choose to start learning Lua... and I started working on this myself. It's quite hard, and I actually don't think it's possible. (I've seen one other server with it but still don't know how he did it.)
I then stopped working on it, but if anyone is interested at taking a look at the code here you go (but it's unfinished and won't ever be finished.)


Code: [Select]
if (SERVER) then
local tmp = 0
AddCSLuaFile("autorun/tags.lua")
/*--------------------------------------------------------------------------
    Start Config
*/--------------------------------------------------------------------------
 
local DATABASE_HOST = "*****"        --Host
local DATABASE_PORT = 3306                     --Port
local DATABASE_NAME = "*****"            --Database
local DATABASE_USERNAME = "*****"                --Username
local DATABASE_PASSWORD = "*****"            --Password
 
/*--------------------------------------------------------------------------
    End Config - Do not edit below this unless you know what you're doing!
*/------------------------------------------------ -------------------------
 
 
/*--------------------------------------------------------------------------
    Server Logging V2 - By Trivkz
*/------------------------------------------------ -------------------------
 
require("mysqloo")
local db = mysqloo.connect(DATABASE_HOST, DATABASE_USERNAME, DATABASE_PASSWORD, DATABASE_NAME, DATABASE_PORT)
db.onConnectionFailed = function() print("++++++++++++++++Failed Connection+++++++++++++++++++++++") end
db.onConnected = function() print("  ++++++++++++++++++Successfully Connected to DB+++++++++++++++++++++++") ScanForChanges() end
db:connect()

function Querys()

 local query1 = db:query("CREATE TABLE mChat (server INTEGER UNSIGNED NOT NULL ,player INTEGER UNSIGNED NOT NULL,said VARCHAR(255) NULL,PRIMARY KEY (server));");
  query1.onData = function() print("Anything at all") end
  query1.onSuccess = function() print("++++++++++++++++++Successfull Query+++++++++++++++++++++++") Query2() end
  query1.onFailure = function() print("Error Printing Query!") end
  query1.onError = function(error_message) print(error_message) print("ERROR YOU STUPID MOTHERFUCKER JESUS H CHRIST") end
  query1:start()
end
function Query2()
local sid = db:escape("Boo")

  local query1 = db:query("INSERT into mChat ( server, player,said) VALUES ( 2, 0,'" .. sid .. "');")
  --local query1 = db:query("SELECT * FROM mChat WHERE server = 1;")
  -- query1.onData = function(Q,D) print("Q1") PrintTable(D) end
  query1.onSuccess = function() print("++++++++++++++++++Successfull Query2+++++++++++++++++++++++")  PrintTable(query1:getData())

local Table = query1:getData()
local servernum = Table[1].server
servertxt = Table[1].said

print("This value is what your looking for "..tostring(servernum))
end
  query1.onFailure = function() print("Error Printing Query!") end
  query1.onError = function(error_message) print(error_message) print("ERROR DURING QUERY") end
  query1:start()
 
end

function playerSaid( ply, saywhat )

servertxt = saywhat
if (tmp == 0) then
ScanForChanges()
tmp = 1
end
end
hook.Add ( "PlayerSay", "playerSaid", playerSaid )

-- function QueryRepeat(ply)
  -- local query1 = db:query("INSERT into mChat ( server, player,said) VALUES ( 1, 0,'" .. sid .. "');")
  -- local query1 = db:query("SELECT * FROM mChat WHERE server = 1;")
  -- query1.onData = function(Q,D) print("Q1") PrintTable(D) end
  -- query1.onSuccess = function() print("Success")

-- local Table = query1:getData()
-- local servernum = Table[1].server
-- dbtxt = Table[1].said

-- if ((dbtxt ~= servertxt) and (servertxt ~= nil)) then
-- local update = db:query("UPDATE mChat SET said = '" .. servertxt .. "' WHERE server = 1;")
-- update.onSuccess = function()
-- ply:SendLua(string.format("chat.AddText( %q );", servertxt))
-- end
-- update:start()
-- timer.Create("query", 0.1, 0, function()
-- QueryRepeat(ply)
-- end)
-- else
-- timer.Create("query", 0.1, 0, function()
-- QueryRepeat(ply)
-- end)

-- end

-- end
  -- query1.onFailure = function() print("Error Printing Query!") end
  -- query1.onError = function(error_message) print(error_message) print("ERROR DURING QUERY") end
  -- query1:start()
 
-- end

function ScanForChanges()

  --local query1 = db:query("INSERT into mChat ( server, player,said) VALUES ( 1, 0,'" .. sid .. "');")
  local query1 = db:query("SELECT * FROM mChat WHERE server = 2;")
  --query1.onData = function(Q,D) print("Q1") PrintTable(D) end
  query1.onSuccess = function() print("Success")

local Table = query1:getData()
--local servernum = Table[2].server
local dbtxt = Table[1].said

if ((dbtxt ~= servertxt) and (servertxt ~= nil)) then
local update = db:query("UPDATE mChat SET said = '" .. servertxt .. "' WHERE server = 2;")
update.onSuccess = function()
local Players = player.GetAll()
for i = 1, table.Count(Players) do
local ply = Players[i]
ply:SendLua(string.format("chat.AddText( %q );", servertxt))
end
timer.Create("queryrepeat", 0.1, 0, function()
ScanForChanges()
end)
end
update:start()
elseif (dbtxt == servertxt) then

timer.Create("queryrepeat", 0.1, 0, function()
ScanForChanges()
end)

end



end
  query1.onFailure = function() print("Error Printing Query!") end
  query1.onError = function(error_message) print(error_message) print("ERROR DURING QUERY") end
  query1:start()
 
end


end

if (CLIENT) then
local servertxt
local function RecvMyUmsg( data )
 
servertxt = data:ReadString();
print (servertxt)

 
end
usermessage.Hook( "MyUsermessage", RecvMyUmsg );


function Insert( pl, msg )
local ServerNum = "#1 "
local tab = {}
table.insert( tab, Color( 62, 165, 255, 255 ) )
table.insert( tab, "1 " )
table.insert( tab, team.GetColor( pl:Team() ) )
table.insert( tab, pl:Nick() )
table.insert( tab, Color( 255, 255, 255, 255 ) )
table.insert( tab, ": " )
table.insert( tab, msg )

chat.AddText( unpack(tab) )
return true
end

end

hook.Add("OnPlayerChat", "InsertTags", Insert)



*edit by MrP: Put the code in code tags*
« Last Edit: June 30, 2012, 03:22:02 AM by MrPresident »
Quote from: John F. Kennedy 1963
A man may die, nations may rise and fall, but an idea lives on.