SMF Player registration + a question regarding SRCDS restarting

This will allow you to register players onto your SMF forums from in-game.


local db = mysqloo.connect(“localhost”, username, pw, “smf”, 3306)

function iPly.SMF_register (username, password, email)
local username = iA.filter(username)

if (not email) or (string.len(email)<4) then email = "invalid" end

register_vars = {
    memberName = "'" .. username .. "'",
    realName= "'" .. username .. "'",
    emailAddress= "'" .. (email or "") .. "'",
    passwd= "'" .. string.lower(crypto.sha1(string.lower(username) .. password)) .. "'",
    passwordSalt= "'" .. string.sub(string.lower(crypto.md5(tostring(math.random(0,2147483647)))), 0, 4) .. "'",
    posts= '0',
    dateRegistered= tostring(os.time()),
    is_activated= '1',
    personalText= "''",
    pm_email_notify= '1',
    ID_THEME= '0',
    ID_POST_GROUP= '4',
    lngfile= "''",
    buddy_list= "''",
    pm_ignore_list= "''",
    messageLabels= "''",
    websiteTitle= "''",
    websiteUrl= "''",
    location= "''",
    ICQ= "''",
    AIM= "''",
    YIM= "''",
    MSN= "''",
    timeFormat= "''",
    signature= "''",
    avatar= "''",
    usertitle= "''",
    memberIP= "''",
    memberIP2= "''",
    secretQuestion= "''",
    secretAnswer= "''",
    validation_code= "''",
    additionalGroups= "''",
    smileySet= "''",
    --passwordSalt= "''",    


local function keys(tbl)
    local out = {}
    for k,v in pairs(tbl) do
        table.insert(out, k)
    return out

local function itable(tbl)
    local out = {}
    for _,v in pairs(keys(tbl)) do
        table.insert(out, tbl[v])
    return out

local id
local query = "INSERT INTO smf_members (" .. string.Implode(', ', keys(register_vars)) .. ") VALUES (" .. string.Implode(', ', itable(register_vars)) .. ')'
local q1 = db:query(query)
q1.onError = function(q, err) print ("MYSQLOO ERROR iPly.SMF_register: " .. err) return end

local q2 = db:query("UPDATE smf_settings SET value = value + 1 WHERE variable = 'totalMembers' LIMIT 1")
q2.onError = function(q, err) print ("MYSQLOO ERROR iPly.SMF_register_totalmembers: " .. err) return end

--[[tmysql.query("REPLACE INTO members (variable, value) VALUES ('latestMember', " .. id .. "), ('latestRealName', '" .. username .. "')", function(res, stat, err)
    if stat == 0 then print ("TMYSQL ERROR iPly.SMF_register_latestmember: " .. err) return end


concommand.Add(“testregister”, function(ply, cmd, args)
if not iA.isOwner(ply) then return end
for k,v in pairs(args) do
args[k] = iA.filter(v)
iPly.SMF_register(args[1], args[2], args[3])

My question:

Recently Serverchecker hasn’t really been cutting it. I’m not sure if I am the only one having this issue, but since about two weeks ago, the server would frequently double, triple, or quadruple restart in intervals of 90 seconds or whatever I have the “Startup time” variable set to. This is not tolerable because it can lose many players after a server crash.

A .bat file also doesn’t cut it, because sometimes SRCDS hangs instead of crashing, which the .bat file won’t detect. If you’re wondering why my server crashes so often, it is because it is a build server.

What I’m looking for is someone able to program in a different language (maybe C++?) that can make a server checker. It wouldn’t need to be real nice, just something that can detect when the server is offline and restart it. I’m not exactly sure how one pings a gameserver, but I could also use other mechanisms, maybe with gm_socks. I’d learn C++ myself but it’s very difficult to get started and I’d rather finish working on the gamemode I am working on.

If someone can help me code a server restarter script, that works well, I will even pay you $20 if it works, $30 if it is easy to use.

You talking about a remote server checker?

No, a local Serverchecker that I can put on my dedicated server, like Dumbclan’s except not causing double/triple restarts for no reason. Dumbclan’s is also buggy in other ways.

I got one in C++, should be working. However, it’s not very configurable at the moment. I could give you the source if you want?


nevermind, apparently the source disappeared

I have a lua script that detects hangs and deletes everything in the perpetrator’s undo history and kicks him. You can use that with a .bat.

I wrote this in C# really quickly, but AFAIK it works. You need to provide it with two arguments- The name of the srcds process without extension and the path to start srcds if it cannot find it with extension. It doesn’t do anything fancy, like check if its hanging or anything, it’s pretty simple.

It waits 10 seconds between restart checks, but I’ll change that now, seems kind of often.

Okay, this one waits 30 seconds between checks.

You don’t have a lua script that can detect hangs. Also, you might want to use patterns to verify that it is indeed an email address.

This here should cut the cheese.

[lua]local sub , domain , rootname = string.gmatch(email , “(.+)%s@(.+)%s%.(.+)%s”)()

if sub and domain and rootname then[/lua]

[lua]local id, domain, top = email:match( “(.+)@(.+)%.(.+)” )[/lua]

The whitespaces (%s) break it. Also, why gmatch instead of match?

I’ve no idea. It’s only recently I’ve been learning how to use patterns.

Both of those are corrupted, and I’m unable to extract them. I’m using WinRAR so it shouldn’t be an issue. Anyways, 10 seconds is better, except it would be good to have a startup timer of 30 seconds because the server might take a few seconds to come online.

Also, I’m not sure what you are doing Flapjack, what does email addresses have anything to do with his script? Am I the only one not able to extract his exe?

function iPly.SMF_register (username, password, **email**)

Someone could input something that’s not an email address.

They work for me

I see FlapJack, I never registered people with email addresses so I never noticed it.

Can someone please extract Whitewater’s two 7zip files into rar or zip? WinRAR is usually able to open any kind of archive, not sure why it’s not working in this case.

 Unkown method in SRCDSRestarter.exe
Error - operation failed 

Those files open for me, but won’t extract.
7z says “Unsupported compression method”

********passwd= “’” … string.lower(crypto.sha1(string.lower(username) … password)) … “’”,
********passwordSalt= “’” … string.sub(string.lower(crypto.md5(tostring(math.random(0,2147483647)))), 0, 4) … “’”,

The fuck are you doing, I thought passwords were md5 and password salts were: md5(md5(pass)…salt)

I decided to just go with zip this time. Added a third argument, number of milliseconds to wait between checks.
Also included source.


iRzilla, I suggest you look at the SMF API sample code, which is where I got this from. The password is a SHA1, and the salt is a completely random string.

EDIT: iRzilla, I see what you’re getting at, after doing some research it seems like what should be stored in the database is a salted hash and the salt, and in this case it seems like we’re storing nonsalted-hash and salt. I’m not sure how SMF does it, but this is also how it is stated in the SMF API (which is in PHP).

Additionally, the code is tested and works.

Whitewater I will test your code and post back soon.

Eh I feel like a fool now, should of done a little research before posting;

$current = sha1(strtolower('username') . 'password');
$salt = substr(md5(rand()), 0, 4);

That is how it’s done in PHP. I think I can see one small fault in your script though. You’re using string.lower on the SHA1 encryption on the password. Is SHA1 not case sensitive?

I think you may be right, the script may be making all passwords into lower case, which is definitely not a good thing.

[editline]2nd January 2011[/editline]

Whitewater, I run more than one SRCDS.exe on my Dedicated server, so your script isn’t suitable. Can you please rework it so that it actually launches SRCDS and keeps track of its process ID? Also it’s unclear how I am supposed to do the parameters, should it be SRCDSRestarter.exe -processname -C:/dir/srcds.exe -1000 ?

If it works I can pay you as I said in OP, $20-30. It should have these parameters:
-Startup timer (the server can take a while to start, don’t restart it during this time)
-Timeout (how often it checks)
-Directory to the executable, as well as parameters to run on the executable

Your issue isn’t with ServerChecker it is that you are using it incorrectly, source queries are not a very reliable method to check if your server needs to be restarted or not because there is a limit to how many queries a server can respond to in a timespan as well as them possibly being not sent because of an overloaded server.

ServerChecker does all of the stuff you are wanting and you already have it, properly configure the settings for the queries or just use it in normal program mode.