public static void GuidOK(NetConnection conn, Guid guid) { var data = new NetBuffer(); var logger = Logger.Instance(); var store = GUIDStore.Instance(); data.Write((Int32)Packets.Server.GuidOK); data.Write(guid.ToString()); data.Write(store.GetID(guid)); logger.Write(String.Format("Sending GuidOK to {0}", NetUtility.ToHexString(conn.RemoteUniqueIdentifier)), LogLevels.Debug); SendDataTo(conn, data); }
private static void HandleLoginRequest(NetIncomingMessage msg) { var logger = Logger.Instance(); logger.Write(String.Format("Received LoginRequest from {0}", NetUtility.ToHexString(msg.SenderConnection.RemoteUniqueIdentifier)), LogLevels.Informational); // Retrieve our username and password from the message. var user = msg.ReadString(); var pass = msg.ReadString(); // Attempt to authenticate the user. var result = Data.AuthenticateUser(user, pass); if (result[0] == 0) { // Login OK. // Generate a brand new GUID and add our user to the internal storage for later use. var id = result[1]; var guid = Guid.NewGuid(); var storage = GUIDStore.Instance(); storage.AddGUID(id, guid); logger.Write(String.Format("Authenticated user at Peer: {0}", NetUtility.ToHexString(msg.SenderConnection.RemoteUniqueIdentifier)), LogLevels.Debug); logger.Write(String.Format("Added GUID: {0} to storage.", guid), LogLevels.Debug); // Send our user the OK and our realmlist. Send.AuthSuccess(msg.SenderConnection, guid); } else { // Login Failed. logger.Write(String.Format("Authentication failed for user at Peer: {0}", NetUtility.ToHexString(msg.SenderConnection.RemoteUniqueIdentifier)), LogLevels.Debug); // Tell our user they entered incorrect information. Send.AuthFailed(msg.SenderConnection); } }
private static void HandleConfirmGuid(NetIncomingMessage msg) { var logger = Logger.Instance(); logger.Write(String.Format("Received ConfirmGuid from {0}", NetUtility.ToHexString(msg.SenderConnection.RemoteUniqueIdentifier)), LogLevels.Informational); var store = GUIDStore.Instance(); // See if our storage contains this Guid. var guid = Guid.Parse(msg.ReadString()); if (store.Contains(guid)) { // Yes it does, we can accept this client. logger.Write(String.Format("GUID: {0} Exists, allowing user on.", guid), LogLevels.Debug); Send.GuidOK(msg.SenderConnection, guid); } else { // No it doesn't, where did they come from? logger.Write(String.Format("GUID: {0} Does NotExists, notify user.", guid), LogLevels.Debug); Send.GuidError(msg.SenderConnection, guid); } }