Alright, I made quite a few changes. I have no idea if this is going to work, but it compiled. It should be using Asynchronous UDP Sockets (an OK guide here: http://msdn.microsoft.com/en-us/libr...inreceive.aspx). I also added the Insert but Update on Duplicate key assuming the key is composite (IP and Port Combo)... else it won't work. If it's not a composite key, use the old method... it's still in the code but commented. Hopefully I called ReceiveMessages() method appropriately. I'm not exactly sure here.
I put my source in the OwN-3m-All folder in MoHAABox. Please check it out Razo... See what you think... it needs to be tested... make backups before running lol! Again, not sure if the call to run ReceiveMessages() method is in the correct place or should be called infinitely using the while(true).
Assuming the primary key is a composite key consisting of IP and port, this method should work:
Code:
// Try to insert a new server ip and port --- If the IP and port already exist, update online and lastcheck
public bool InsertUpdate(string ip, int port)
{
// Documented example:
/* INSERT INTO table (a,b,c) VALUES (1,2,3) ON DUPLICATE KEY UPDATE c=c+1; */
string query = "INSERT INTO server (IP, Port, LastCheck) VALUES('" + ip + "', '" + port.ToString() + "', NOW()) ON DUPLICATE KEY UPDATE LastCheck=NOW(), Online='1'";
bool res = true;
//open connection
if (this.OpenConnection() == true)
{
//create command and assign the query and connection from the constructor
MySqlCommand cmd = new MySqlCommand(query, connection);
try
{
//Execute command
cmd.ExecuteNonQuery();
}
catch (MySqlException ex)
{
log.writeLine(ex.Message);
res = false;
}
//close connection
this.CloseConnection();
}
return res;
}