Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GM.Database = {}
- GM.Database.address = "107.180.56.150"
- GM.Database.username = "bcbest"
- GM.Database.password = "bc7475bc"
- GM.Database.port = 3306
- GM.Database.database = "callofgmod"
- GM.Database.ReconnectTime = 30
- GM.Database.Queue = {}
- local database_object
- local cfg = Gamemode.Config
- require("tmysql4")
- function DatabasePrint(msg)
- if cfg.Debug then
- MsgN("[WarGame] Database: "..msg)
- end
- end
- function GM.Database:connect(host, user, pass, db, port)
- local error
- database_object, error = tmysql.initialize( host, user, pass, db, port)
- if error then
- DatabasePrint("Error - "..error)
- DatabasePrint("Retrying connection in "..tostring(GM.Database.ReconnectTime).." seconds!")
- timer.Simple(GM.Database.ReconnectTime, function()
- GM.Database:connect(host, user, pass, db, port)
- end)
- end
- if database_object then
- print("\n[WarGame] Database: Connected Succesfully!\n")
- end
- end
- function GM.Database:escape(str)
- -- Check if we have a connection?
- if (database_object) then
- return database_object:Escape(str)
- else
- return str
- end
- end
- function Gamemodequery(query, callback)
- -- Check if we have a connection ;)
- if (not database_object) then
- GM.Database:connect(GM.Database.address, GM.Database.username, GM.Database.password, GM.Database.database, GM.Database.port)
- database_object:Query(query, function(cb)
- if (callback) then
- callback(cb[1].data)
- end
- end)
- end
- -- Query
- return database_object:Query(query, function(cb)
- if (callback) then
- callback(cb[1].data)
- end
- end)
- end
- GM.Database:connect(GM.Database.address, GM.Database.username, GM.Database.password, GM.Database.database, GM.Database.port)
- Gamemodequery([[CREATE TABLE IF NOT EXISTS `players`
- (
- `id` INT AUTO_INCREMENT PRIMARY KEY,
- `uid` BIGINT(20),
- `name` TEXT,
- `level` INT,
- `xp` INT
- )
- COLLATE='latin1_swedish_ci'
- ENGINE=MyISAM;
- ]], function()
- DatabasePrint("Succesfully created table 'players'!")
- end)
- Gamemodequery([[CREATE TABLE IF NOT EXISTS `sv_settings`
- (
- `gamemode` TEXT
- )
- COLLATE='latin1_swedish_ci'
- ENGINE=MyISAM;
- ]], function()
- DatabasePrint("Succesfully created table 'sv_settings'!")
- end)
- Gamemodequery([[
- SELECT `gamemode` FROM `sv_settings`;
- ]], function(cb)
- if not cb then
- Gamemodequery([[
- INSERT INTO `sv_settings` (`gamemode`)
- VALUES ("tdm");
- ]])
- DatabasePrint("The gamemode was not set. The server set the gamemode to Team Death Match!")
- else
- DatabasePrint("The server has a gamemode. No need to rewrite it!")
- end
- end)
- function GM:PlayerInitialSpawn(ply)
- local function CheckIfThere(tbl, val)
- for k, v in pairs(tbl) do
- if v.uid == val then
- return true
- end
- end
- return false
- end
- Gamemodequery([[
- SELECT `uid` FROM `players`;
- ]], function(cb)
- if not CheckIfThere(cb, ply:SteamID64()) then
- Gamemodequery([[
- INSERT INTO `players` (`uid`, `name`)
- VALUES ("]]..ply:SteamID64()..[[", "]]..ply:Nick()..[[");
- ]])
- DatabasePrint(ply:Nick().."'s' data was not found and we have just wrote it!")
- end
- DatabasePrint(ply:Nick().."'s' data was found!")
- end)
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement