public override User[] GetAllUsers() { MySqlConnection conn = new MySqlConnection(connStr); User[] allUsers = null; try { conn.Open(); int count = GetCount(); int i = 0; allUsers = new User[count]; string sql = "SELECT `name`,`top`,`left`,`z` FROM " + userTableName; MySqlCommand cmd = new MySqlCommand(sql, conn); MySqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read() && i <= count) { ulong userName = rdr.GetUInt64(0); allUsers[i] = new User(); allUsers[i].n = IPulongToString(userName); //allUsers[i].Name = rdr.GetString(0); allUsers[i].p.t = rdr.GetInt32(1); allUsers[i].p.l = rdr.GetInt32(2); allUsers[i].p.z = rdr.GetInt32(3); i++; } rdr.Close(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } conn.Close(); return allUsers; }
/// <summary> /// Broadcasts a position message to all online users /// </summary> /// <param name="Message">The chat message to be broadcasted</param> /// <param name="AContext">The user's connection context</param> private static void SetPosition(RCATContext RContext, ServerMessage message) { try { User user = new User(); user = (User)serializer.Deserialize(new JTokenReader(message.Data), typeof(User)); dataConnector.SetPosition(user.n, user.p, message.TimeStamp); string[] clients = dataConnector.GetAllUsersNames(); dynamic data = new { n = user.n, p = user.p }; RContext.Broadcast(data, clients, ResponseType.Position, message.TimeStamp); } catch (Exception e) { Log.Error(e); } }
public static void RefreshAllUsers(object source, ElapsedEventArgs e) { MySqlConnection conn = new MySqlConnection(connStr); try { int count = GetCountStatic(); conn.Open(); int i = 0; string[] tmpUserNames; User[] tmpUsers; tmpUsers = new User[count]; tmpUserNames = new string[count]; string sql = "SELECT `name`,`top`,`left`,`z` FROM " + userTableName; MySqlCommand cmd = new MySqlCommand(sql, conn); MySqlDataReader rdr = cmd.ExecuteReader(); while (rdr.Read() && i <= count) { ulong userName = rdr.GetUInt64(0); tmpUsers[i] = new User(); tmpUsers[i].n = IPulongToString(userName); tmpUserNames[i] = tmpUsers[i].n; users[userName] = tmpUsers[i]; tmpUsers[i].p.t = rdr.GetInt32(1); tmpUsers[i].p.l = rdr.GetInt32(2); tmpUsers[i].p.z = rdr.GetInt32(3); i++; } rdr.Close(); Interlocked.Increment(ref refreshing); allUsers = tmpUsers; allUserNames = tmpUserNames; aTimer.Enabled = true; Interlocked.Decrement(ref refreshing); userRefresh.Set(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); aTimer.Enabled = true; } conn.Close(); }
public User GetUserFromDatabase(string userName) { MySqlConnection conn = new MySqlConnection(connStr); User user = null; try { conn.Open(); ulong name = IPStringToulong(userName); string sql = string.Format("SELECT * FROM " + userTableName + @" WHERE name = {0}", name); MySqlCommand cmd = new MySqlCommand(sql, conn); MySqlDataReader rdr = cmd.ExecuteReader(); user = new User(); if (rdr.Read()) { user.n = userName; user.p.t = rdr.GetInt32(1); user.p.l = rdr.GetInt32(2); } rdr.Close(); } catch (Exception ex) { Console.WriteLine(ex.ToString()); } conn.Close(); return user; }