ID:151902
 
Well just today I was randomly inspired to make a demo on a mysql save server, firstly before I get your ideas on this I would like to know if this kind of savefile system is secure or "secure-er" than saving on say the hosts computer.

Personally, I think this type of system is better for editing as I can easily edit a player through phpmyadmin but still I would like some ideas on this and how many of you will actually use this demo.

I am mainly making this for my own use but releasing it as a Demo would be nice, and I know that there are probally many others who have actually released a demo as such.

Thanks for reading this.

Haywire
Haywire wrote:
firstly before I get your ideas on this I would like to know if this kind of savefile system is secure or "secure-er" than saving on say the hosts computer.

The sql database would be on "the host's" computer, just a different host's computer (at least, from what you're saying sounds like, but it could very well be on the same computer). As long as no data is routed through the clients' computers, security is the same whether the sql server is the same machine as the rest of the game or not.
In response to Loduwijk
Well me being the host, I'm sure I can trust myself :) But honestly I just want to build it due to inspiration and what I really want to know is what people think of the idea, I shoudn't have written about the security as I already knew...more or less about it, but hey more knowledge for me :D

Haywire
In response to Haywire
That sounds really neat, you could store your saves on a 24/7 webhosting service that provides mySQL and all save-transfer problems on games with server-side saves would be solved. I didn't know BYOND supported mySQL, otherwise I would probably already have done this myself, but if you throw out a library that does it, you'll save me some work =)
In response to CIB
I believe Alathon has one, Go look :)

-Haywire
In response to Haywire
He has two, though I don't get the difference between them. Also, do you think it is possible to store the savefile as a whole in a single text-string or should I create columns for each property? Things like editing saves are no priority for me, if need be, I can code a verb into the game for that.
In response to CIB
Well, Personally I would save each type of data (Name,Level, Class, etc.) in a different column due to it being much neater aswell as being easier to handle.

Saving in one file like "Haywire.4.Mage (Name.Level.Class)" would be OK but it would require more parsing to get the necessary data through.

Like:
var/data = "Haywire.4.Mage" //it would actually be through mysql_queries but for this example it is a direct assignment.
var/name = copytext(data,1,".")//parsing


and it would become slightly more difficult, but honestly I would save each stat in a different coloumn for personal reasons.

But you choose what is best for you...

Haywire
In response to CIB
Also here is something I whipped up.

DM Code
mob
verb
Send_Message_To_Server(txt as text)
spawn(1) world.Export("http://domainname.com/BYOND/DM2Server.php?msg=[html_encode(txt)]")
src << "Data sent to Server"

world
Topic(txt)
if(txt)
if(findtext(txt,"Output:"))
world << copytext(txt,8)


PHP Code
<?php

function export($addr,$port,$str)
{
if($str{0} != "?") $str = ("?" . $str);
$query = "\x00\x83" . pack("n",strlen($str)+6) . "\x00\x00\x00\x00\x00" . $str . "\x00";
$server = socket_create(AF_INET,SOCK_STREAM,SOL_TCP) or exit('Unable to create export socket; ' . socket_strerror(socket_last_error()));
socket_connect($server,$addr,$port) or exit('Unable to establish socket connection; ' . socket_strerror(socket_last_error()));
$bytessent = 0;
while($bytessent < strlen($query))
{
$result = socket_write($server,substr($query,$bytessent),strlen($query)-$bytessent);
if($result === FALSE) exit('Unable to transfer requested data; ' . socket_strerror(socket_last_error()));
$bytessent += $result;
}
socket_close($server);
}

//just me logging stuff as usual
$msg = $_GET["msg"];
$file = fopen("Recieved.txt","a+");
fwrite($file,$msg);
fclose($file);


export("IP address","PORT number","Output:" . $msg);
//EXAMPLE : export("123.45.56.78",4543,"Output:" . $msg);

?>


Go Test it. Also thanks to Mobius, Crispy that I got that export() function, I have no idea how it works. Infact I may look it up right now!

:)

Haywire
In response to Haywire
Hm, even nicer, I could send savefiles over the network and let the server handle them via a PHP script like this. I never thought of that solution.
In response to CIB
=)

I may aswell make a libary for this, once I make this for my RPG.

-Haywire
In response to CIB
CIB wrote:
He has two, though I don't get the difference between them.

The 'MySQL' library tries to emulate tables with table objects and a centralized way to save and load from the database, including translating variables DM -> MySQL and the other way around (f.ex converting say, a reference to a location into an actual location). Unfortunately, the library ended up being quite annoying to use. When I have time, I'll go back and revise it to be more user friendly - It works well, its just occasionally complicated.

SimpleMySQL is more or less what the name indicates - It handles the DBConnection for you, provides an easy way to create queries and automagically handles closing them in the background so you never have to worry about that. It also provides a few text formatting procedures. Ex:

var/DBQuery/Q = mysql.CreateQuery()
Q.Execute(SQLFormat_Select(table_name, list_of_fields_to_select, WHERE_clause_here))


This minimizes human error by preventing the need to actually construct the strings yourself. Normally you'd need to check whether the DBConnection was active, then create the query, Execute() a query and then Close() it afterwards and delete the query object (or write a system to re-use it). SimpleMySQL either operates by deleting queries after a timeout period, or re-uses a list of queries as they're available so you aren't constantly creating and deleting queries.