Change to MySQLoo

Hey I could really need someone to change these to lua files so they work with MySQLoo. Currently I use gm_tmysql, but it doesn’t work with linux.

Here’s the two files:

[lua]

if !MySQLLoaded then require(“tmysql”); MySQLLoaded = true; end

function ConnectToMySQL ( )
tmysql.initialize(“localhost”, “root”, “1234”, “roleplay_db”, 3306, 8, 9)
end

ConnectToMySQL();

function GM.SetTeam ( Player, Hint )
if Hint < 5 then
Player:Give(‘weapon_physgun’);
end
end

RunConsoleCommand(‘sv_alltalk’, ‘0’);
[/lua]

[lua]
if !MySQLLoaded then require(“tmysql”); MySQLLoaded = true; end

local OldQuery = tmysql.query;
local LastCame = CurTime();

local function HandleError ( Results, One, Two )
end

local MySQLQueue = {};
local MySQLQueue_Slow = {};
local WhatsThis = {};
local StopItAll = true;

local MySQLQueryDelay = .2;
local MySQLQueryDelay_Slow = 2;
local NextMySQLQuery = CurTime();
local NextMySQLQuery_Slow = CurTime();

local AvgShit = {};

function SetMaxVisiblePlayers ( Num )
RunConsoleCommand(“sv_visiblemaxplayers”, tostring(Num));
PE_MaxVisiblePlayers = Num;
end

function TMysqlQueryThink ( )
if !StopItAll then return false; end

if CurTime() &gt;= NextMySQLQuery and table.Count(MySQLQueue) != 0 then
	for k, v in pairs(MySQLQueue) do
		tmysql.query_direct(v[1], v[2]);
	
		MySQLQueue[k] = nil;
		break;
	end
end

if CurTime() &gt;= NextMySQLQuery_Slow and table.Count(MySQLQueue_Slow) != 0 then
	for k, v in pairs(MySQLQueue_Slow) do
		tmysql.query(v[1], v[2]);
	
		MySQLQueue_Slow[k] = nil;
		break;
	end
	
	NextMySQLQuery_Slow = CurTime() + MySQLQueryDelay_Slow;
end

for k, v in pairs(WhatsThis) do
	if v[2] + 1 &lt; CurTime() then
		StopItAll = nil;
		Msg(v[1] .. '

');

		if file.Exists('what.txt') then
			file.Write('what.txt', file.Read('what.txt') .. '

’ … v[1]);
else
file.Write(‘what.txt’, v[1]);
end

		//file.Write('what_diag.txt', TableToKeyValues(AvgShit));
		
		if isDedicatedServer() then
			timer.Simple(10, RunConsoleCommand, "changelevel", game.GetMap());
		end
		
		for k, v in pairs(player.GetAll()) do
			v:PrintMessage(HUD_PRINTTALK, "Fatal MySQL error. Restarting server. Report to administrator.");
		end
		
		return false;
	end
end

end
hook.Add(‘Think’, ‘TMysqlQueryThink’, TMysqlQueryThink);

local NumQs = 0;

function ShowQPS ( )
Msg('Total: ’ … NumQs … ’
');
Msg('Per Second: ’ … NumQs / CurTime() … ’
');
Msg('Queued: ’ … table.Count(MySQLQueue) … ’
');
Msg('Slow Queued: ’ … table.Count(MySQLQueue_Slow) … ’
');
end
concommand.Add(‘qps’, ShowQPS);

local WriteBuffer = “”;
local LastWriteTime = CurTime();
function SendToWriteAPI ( What )
local Year = os.date("%Y");
local Month = os.date("%m [ %B ]");
local Day = os.date("%d [ %A ]");
local Hour = os.date("%H");
local Minutes = os.date("%M");
local Seconds = os.date("%S");

WiteBuffer = WriteBuffer .. "

[" … Hour … “:” … Minutes … “:” … Seconds … “]” … What;

if LastWriteTime + 60 &gt; CurTime() then return end

LastWriteTime = CurTime();

local LogPath = "mysql_logs/" .. Year .. "/" .. Month .. "/" .. Day .. "/";

local LogPath_Day = LogPath .. "full.txt";
local LogPath_Hour = LogPath .. Hour .. ".txt";

PE_CreateLogs();

if file.Exists(LogPath_Day) then
	file.Write(LogPath_Day, file.Read(LogPath_Day) .. WriteBuffer);
else
	file.Write(LogPath_Day, WriteBuffer);
end

if file.Exists(LogPath_Hour) then
	file.Write(LogPath_Hour, file.Read(LogPath_Hour) .. WriteBuffer);
else
	file.Write(LogPath_Hour, WriteBuffer);
end

WriteBuffer = "";

end

function tmysql.query ( Query, Function, LikedySplit )
if LikedySplit then
tmysql.query_direct(Query, Function);
else
table.insert(MySQLQueue, {Query, Function});
end
end

function tmysql.query_slowstack ( Query, Function, LikedySplit )
table.insert(MySQLQueue_Slow, {Query, Function});
end

function tmysql.query_direct ( Query, Function )
if !StopItAll then return false; end
if !Query or string.lower(type(Query)) != “string” then return false; end

AvgShit[tostring(Function)] = AvgShit[tostring(Function)] or {Query, 0};
AvgShit[tostring(Function)][2] = AvgShit[tostring(Function)][2] + 1;

NextMySQLQuery = CurTime() + MySQLQueryDelay;

NumQs = NumQs + 1;

table.insert(WhatsThis, {Query, CurTime()});

if string.find(string.lower(Query), "truncate") then
	if !file.Exists('alarming_mysql.txt') then file.Write('alarming_mysql.txt', '') end
	file.Write('alarming_mysql.txt', file.Read('alarming_mysql.txt') .. Query);
end

SendToWriteAPI(Query);

if !Function or type(Function) != "function" then
	OldQuery(Query,
		function ( Results, One, Two )
			HandleError(Results, One, Two);
			
			for k, v in pairs(WhatsThis) do
				if v[1] == Query then
					WhatsThis[k] = nil;
				end
			end
		end
	);
else
	OldQuery(Query,
		function ( Results, One, Two )
			HandleError(Results, One, Two);
			PCallError(Function, Results);
			
			for k, v in pairs(WhatsThis) do
				if v[1] == Query then
					WhatsThis[k] = nil;
				end
			end
		end
	);
end

end

local NumQueries = 0;
local TotalNumQueries = 0;
function MySQLQuery ( Database, String, Type )
Error(“Using old MySQL method!”);
end

function ConnectToMySQL ( )
tmysql.initialize(“localhost”, “root”, “1234”, “perp_db”, 3306, 8, 9)

end

ConnectToMySQL();

function GatherPlayerInfos ( Player )
timer.Simple(5, function ( )
if Player and Player:IsValid() and Player:IsPlayer() then
SetupPlayerAccountInfo(Player)
end
end);
end
hook.Add(‘PlayerInitialSpawn’, ‘GatherPlayerInfoss’, GatherPlayerInfos);

function SetupPlayerAccountInfo ( Player )
tmysql.query(“SELECT rank FROM rp_users WHERE steamid=’” … Player:SteamID() … “’”,
function ( GPlayerInfo )
if !GPlayerInfo or !GPlayerInfo[1] then
Player:SetLevel(5);
GAMEMODE.SetTeam(Player, 5);

			PlayerRegister(Player)

			return false;
		else
			local rank = tonumber(GPlayerInfo[1][1])
			Player:SetLevel(rank);
			GAMEMODE.SetTeam(Player, rank);
		end
	end
);

end

function PlayerRegister ( Player )
tmysql.query(“UPDATE rp_users SET rank=‘5’ WHERE steamid=’” … Player:SteamID() … “’”)
end

Msg('Loaded Database Information.
');[/lua]

http://gmodmodules.googlecode.com/svn/trunk/gm_tmysql3_boost/ has a linux build of tmysql.

This is clearly for PERP. Do not request help for stolen gamemodes. Nobody will help you.