The online racing simulator
Insim MySQL Connect
Hello,

I'm using LFSLapper insim, and what I'm attempting to do it connect to an external MySQL server that's on my website host.

All I need to do, is insert one piece of information to a table; it may sound easy but the way I want to do it physically may sound more difficult.

So, when someone connects, I want it to connect to the database, and check against the users table whether their LFSU name already exists in there. If it does then close the database, and take no further action.

If, on the other hand, their name doesn't already exist in the table, it will then add it.

This would prevent multiple copies of the same username within one table. Basically on the website we want a list of all our users.

Thinking of doing it through PHP would be a simple $_POST through in input form, select it from the database, if mysql_num_rows is >=1 then do nothing further, else insert into table. Wish it was just that easy in C#...

Anyone fancies a go?
Thanks in advanced,
3 options;

1. Use constraints (license VARCHAR(32) UNIQUE NOT NULL) and suppress the error/exception on insert failure - simple, quick, although arguably a little hacky as it requires you really suppress the right error to avoid bugs

2. Exactly as you described - how you do this depends on what library you're using to connect to MySQL. Read the documentation?

3. If you want to update something if the user exists (such as last time they were seen, or number of times they've connected) you can do this in one SQL statement by using insert on duplicate update (WARNING: This is MySQL specific)

Since 1 is easy, 2 requires additional information, I'll only describe 3 in more detail.

Assuming a simple table like this:
create table racers(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
license VARCHAR(32) UNIQUE NOT NULL,
data VARCHAR(255),
seen TIMESTAMP DEFAULT UTC_TIMESTAMP
);

The following will attempt to do an insert, otherwise will perform an update storing the last seen time (the UNIQUE license constraint is the magic here):
insert into racers (license, data) values ('the_angry_angel', 'pies') on duplicate key update seen = UTC_TIMESTAMP;

Obviously substitute a parameterized query, or at least filter your inputs through whatever library you're using.
Hello,

Use "http" GLScript command to call a php web page doing what you want.

The result of the http web page must be nothing or a valid GLscript script.

Ex:
http("http://www.frh-team.net/reglapper/getserver2.php" );

this command reply (try adress via web)

privMsg( "^7Actually, there are ^345^7 LFSLapper powered servers");

this reply is processed by LFSLapper and display a private message. You can have more then one line in reply or nothing

In this way you can call a php script via web doing that you explain in your post.

In onConnect event

http("http://yourwebsite/registerPlayer.php&id=" . $userName );

An exemple of reply of this php web page command is

privMsg( "Player added to database");

Or

privMsg( "Player already exist, not added to database");

that's all



Gai-Luron
We have used http("http://website.com/registerPlayer.php&id=" . $userName ); to do the script for example
http://website.com/registerPlayer.php?id=gof[/color] this is the PHP we have, but it doesn't work?
Quote :<?php
$id = $_GET['id'];

include("config.php");

$query = mysql_query("SELECT * FROM racers WHERE license='$id'")or die(mysql_error());

if(mysql_num_rows($query)>=1){
//privMsg("^7User already exists.");
return;
}
else{

mysql_query("INSERT INTO racers (id, license) VALUES('', '$id' ) ") or die(mysql_error());

//privMsg("^7User has been added.");
}
?>

Fix: http("http://website.com/registerPlayer.php&id=".$userName );
Is there an IP player variable?
No, LFS don't provide such info

Gai-Luron
We have tried to do it through $_SERVER['REMOTE_ADDR']; But that returns us with the server IP, so the script must be running server side? not client side
Quote from the_angry_angel :3 options;

1. Use constraints (license VARCHAR(32) UNIQUE NOT NULL) and suppress the error/exception on insert failure - simple, quick, although arguably a little hacky as it requires you really suppress the right error to avoid bugs

2. Exactly as you described - how you do this depends on what library you're using to connect to MySQL. Read the documentation?

3. If you want to update something if the user exists (such as last time they were seen, or number of times they've connected) you can do this in one SQL statement by using insert on duplicate update (WARNING: This is MySQL specific)

Since 1 is easy, 2 requires additional information, I'll only describe 3 in more detail.

Assuming a simple table like this:
create table racers(
id INT NOT NULL AUTO_INCREMENT PRIMARY KEY,
license VARCHAR(32) UNIQUE NOT NULL,
data VARCHAR(255),
seen TIMESTAMP DEFAULT UTC_TIMESTAMP
);

The following will attempt to do an insert, otherwise will perform an update storing the last seen time (the UNIQUE license constraint is the magic here):
insert into racers (license, data) values ('the_angry_angel', 'pies') on duplicate key update seen = UTC_TIMESTAMP;

Obviously substitute a parameterized query, or at least filter your inputs through whatever library you're using.

I tried all three but they seemed relatively difficult so I did the method below :P Thank you for your input anyway

Quote from Gai-Luron :Hello,

Use "http" GLScript command to call a php web page doing what you want.

The result of the http web page must be nothing or a valid GLscript script.

Ex:
http("http://www.frh-team.net/reglapper/getserver2.php" );

this command reply (try adress via web)

privMsg( "^7Actually, there are ^345^7 LFSLapper powered servers");

this reply is processed by LFSLapper and display a private message. You can have more then one line in reply or nothing

In this way you can call a php script via web doing that you explain in your post.

In onConnect event

http("http://yourwebsite/registerPlayer.php&id=" . $userName );

An exemple of reply of this php web page command is

privMsg( "Player added to database");

Or

privMsg( "Player already exist, not added to database");

that's all



Gai-Luron

I was thinking of doing it this way beforehand, but have tried and works a treat. Thanks alot.
Quote from Gai-Luron :No, LFS don't provide such info

Gai-Luron

LFS does provide that info in the log file, but not directly inside of LFS. Some people (cargame) have parsed this on join and created the link between users.
Yes,

but this assume that LFSLapper and LFS server are on the same computer. An other way it's to have LFS server on machine who have http access and make a little script giving IP on web.

Bye

Gai-Luron

FGED GREDG RDFGDR GSFDG