internal static void HandlePlayerMoving(DataBuffer buffer) { var id = buffer.ReadInt32(); if (!Data.TempPlayers.ContainsKey(id)) return; for (var i = 0; i < (Int32)Enumerations.Direction.Direction_Count; i++) { Data.TempPlayers[id].IsMoving[i] = buffer.ReadBoolean(); } }
internal static void HandlePlayerMoving(Int32 id, DataBuffer buffer) { for (var i = 0; i < (Int32)Enumerations.Direction.Direction_Count; i++) { Data.TempPlayers[id].IsMoving[i] = buffer.ReadBoolean(); } for (var i = 0; i < Data.Players.Keys.Count; i++) { var key = Data.Players.ElementAt(i).Key; if (Data.TempPlayers.ContainsKey(key)) { if (Data.TempPlayers[key].InGame) { if (Data.Players[id].Characters[Data.TempPlayers[id].CurrentCharacter].Map == Data.Players[key].Characters[Data.TempPlayers[key].CurrentCharacter].Map) { Send.PlayerMoving(key, id); } } } } }
public static void HandleLogin(Int32 id, DataBuffer buffer) { // Handles a user's request to login. var username = buffer.ReadString().Trim(); var password = buffer.ReadString().Trim(); var isEditor = buffer.ReadBoolean(); // Check if the user isn't sending too long/short data. if (username.Trim().Length < Data.Settings.MinUsernameChar || username.Trim().Length > Data.Settings.MaxUsernameChar || password.Trim().Length < Data.Settings.MinPasswordChar || password.Trim().Length > Data.Settings.MaxPasswordChar) { Send.AlertMessage(id, String.Format("Your username must be between {0} and {1} characters long. Your password must be between {2} and {3} characters long.", Data.Settings.MinUsernameChar, Data.Settings.MaxUsernameChar, Data.Settings.MinPasswordChar, Data.Settings.MaxPasswordChar)); return; } // Check if this account exists. if (!File.Exists(String.Format("{0}data files\\accounts\\{1}.xml", Data.AppPath, username.ToLower()))) { Send.AlertMessage(id, "Invalid Username/Password!"); return; } // Load our player! Data.LoadPlayer(id, username.ToLower()); // Compare their passwords! if (!Data.Players[id].ComparePassword(password)) { Send.AlertMessage(id, "Invalid Username/Password!"); Data.Players[id] = new Extensions.Database.Player(); return; } // Is the account allowed to log in? if (isEditor && Data.Players[id].UserRank < (Int32)Enumerations.Ranks.Developer) { Send.AlertMessage(id, "Invalid Username/Password!"); // We're not going to tell them the real reason. Data.Players[id] = new Extensions.Database.Player(); return; } // Send our OK. Logger.Write(String.Format("ID: {0} has logged in as {1}", id, Data.Players[id].Username)); Send.LoginOK(id); // Disconnect anyone else logged into this account. var oldclient = 0; for (var i = 0; i < Data.Players.Count; i++) { var key = Data.Players.ElementAt(i).Key; if (Data.Players[key].Username.ToLower().Equals(username.ToLower()) && key != id) { oldclient = key; } } if (oldclient != 0) { if (!isEditor && Data.TempPlayers[oldclient].InGame) { Send.AlertMessage(oldclient, "Someone else has logged onto your account!"); Logger.Write(String.Format("ID: {0} conflicts with a login at ID: {1}, Disconnecting ID: {1}", id, oldclient)); Data.SavePlayer(oldclient); // NOTE: the user is still logged on until they get this message, we're saving their data on purpose. // Their data will now be saved twice, but we can safely load it. Data.LoadPlayer(id, username.ToLower()); // Now remove the old player from the world by force. Program.Server.DisconnectClient(oldclient); } else if (isEditor && Data.TempPlayers[oldclient].InEditor) { Send.AlertMessage(oldclient, "Someone else has logged onto your account!"); Logger.Write(String.Format("ID: {0} conflicts with a login at ID: {1}, Disconnecting ID: {1}", id, oldclient)); Data.SavePlayer(oldclient); // NOTE: the user is still logged on until they get this message, we're saving their data on purpose. // Their data will now be saved twice, but we can safely load it. Data.LoadPlayer(id, username.ToLower()); // Now remove the old player from the world by force. Program.Server.DisconnectClient(oldclient); } else { Logger.Write(String.Format("ID: {0} conflicts with a login at ID: {1}, but are in an editor and client", id, oldclient)); } } if (!isEditor) { // Check if they have at least one character. var haschars = false; foreach (var chr in Data.Players[id].Characters) { if (chr.Name.Length > 0) haschars = true; } // If we have characters, show character select. // Otherwise force the user to make a new character. if (haschars) { Send.SelectCharacterData(id); } else { Send.NewCharacterData(id); } } else { Data.TempPlayers[id].InEditor = true; } }