Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using COServer.Client;
- using COServer.Database;
- using System;
- using System.Collections.Generic;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- namespace COServer
- {
- public class PlayersTable
- {
- public static void UpdateOnlineStatus(GameClient client, bool online, MySql.Data.MySqlClient.MySqlConnection conn)
- {
- if (online || (!online && client.DoSetOffline))
- {
- UpdateData(client, "Online", online);
- }
- }
- public static void UpdateOnlineStatus(Client.GameClient client, bool online)
- {
- if (online || (!online && client.DoSetOffline))
- {
- UpdateData(client, "Online", online);
- }
- }
- public static void UpdateData(Client.GameClient client, string column, object value)
- {
- UpdateData(client.Player.UID, column, value);
- }
- public static void UpdateData(uint UID, string column, object value)
- {
- if (value is Boolean)
- {
- using (var cmd = new MySqlCommand(MySqlCommandType.UPDATE))
- cmd.Update("entities").Set(column, (Boolean)value).Where("UID", UID)
- .Execute();
- }
- else
- {
- using (var cmd = new MySqlCommand(MySqlCommandType.UPDATE))
- cmd.Update("entities").Set(column, value.ToString()).Where("UID", UID)
- .Execute();
- }
- }
- private static bool ExistsMyPlayerUID(uint UID)
- {
- using (var cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("entities").Where("UID", UID))
- using (var reader = new MySqlReader(cmd))
- {
- while (reader.Read())
- {
- reader.Close();
- reader.Dispose();
- return true;
- }
- return false;
- }
- }
- public static void InserMyPlayerUID(Client.GameClient client)
- {
- try
- {
- if (!ExistsMyPlayerUID(client.Player.UID))
- {
- using (var cmd = new MySqlCommand(MySqlCommandType.INSERT).Insert("entities"))
- cmd.Insert("UID", client.Player.UID)
- .Execute();
- }
- }
- catch (Exception)
- {
- }
- }
- public static bool InsertWhenLoggIn(GameClient client)
- {
- InserMyPlayerUID(client);
- WindowsAPI.IniFile ini = new WindowsAPI.IniFile("");
- foreach (string fname in System.IO.Directory.GetFiles(Program.ServerConfig.DbLocation + "\\Users\\"))
- ini.FileName = fname;
- uint UID = ini.ReadUInt32("Character", "UID", 0);
- if(UID == 0)
- UID = ini.ReadUInt32("Character", "UID", 0);
- using (var cmd = new MySqlCommand(MySqlCommandType.SELECT).Select("entities").Where("UID", UID))
- using (var reader = new MySqlReader(cmd))
- {
- if (reader.Read())
- {
- client.Player.UID = reader.ReadUInt32("UID");
- return true;
- }
- else
- return false;
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement