private void handleLogIn(PlayerCharacter pc, IncommingMessage msg) { if (pc.LoginState == PlayerCharacterLoginState.ClientVersionCorrect) { LogInIncommingMessage msgLogIn = (LogInIncommingMessage)msg; // Is acceptable character name if (!pcAuthentication.IsAcceptablePlayerName(msgLogIn.UserName)) { LogInNotOkOutgoingMessage msgLogInNotOk = (LogInNotOkOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.LOG_IN_NOT_OK); msgLogInNotOk.Message = "This character name is not acceptable."; pc.PutMessageIntoMyQueue(msgLogInNotOk); return; } // Does character exist if (!pcAuthentication.Exists(msgLogIn.UserName)) { pc.PutMessageIntoMyQueue(msgStdYouDontExist); return; } try { // Check the password if (!pcAuthentication.Authenticate(msgLogIn.UserName, msgLogIn.Password)) { LogInNotOkOutgoingMessage msgLogInNotOk = (LogInNotOkOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.LOG_IN_NOT_OK); msgLogInNotOk.Message = "The password is wrong!"; pc.PutMessageIntoMyQueue(msgLogInNotOk); return; } } catch (Exception ex) { logger.LogError(LogSource.World, "Failed to authenticate player: " + pc.Name, ex); LogInNotOkOutgoingMessage msgLogInNotOk = (LogInNotOkOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.LOG_IN_NOT_OK); msgLogInNotOk.Message = "Server could not load the character!"; pc.PutMessageIntoMyQueue(msgLogInNotOk); return; } // Check if already logged in if (getPlayerByName(msgLogIn.UserName) != null) { LogInNotOkOutgoingMessage msgLogInNotOk = (LogInNotOkOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.LOG_IN_NOT_OK); msgLogInNotOk.Message = "You are already logged in!"; pc.PutMessageIntoMyQueue(msgLogInNotOk); return; } // Clear character (current state of character is undefined!) pc.ClearEntityImplementation(); pc.Name = msgLogIn.UserName; // Temporary setting user name so that deserialization may work // Deserialize user data try { pc.Deserialize(pcDeserializer); } catch (Exception ex) { logger.LogError(LogSource.World, "Failed to deserialize player: " + pc.Name, ex); LogInNotOkOutgoingMessage msgLogInNotOk = (LogInNotOkOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.LOG_IN_NOT_OK); msgLogInNotOk.Message = "Server could not load the character!"; pc.PutMessageIntoMyQueue(msgLogInNotOk); return; } try { // Add to dictionaries / Get EntityID addEntityImplementationToWorld(pc); } catch (Exception ex) { logger.LogError(LogSource.World, "Failed to register player: " + pc.Name, ex); LogInNotOkOutgoingMessage msgLogInNotOk = (LogInNotOkOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.LOG_IN_NOT_OK); msgLogInNotOk.Message = "Server could not register the character!"; pc.PutMessageIntoMyQueue(msgLogInNotOk); return; } // TODO: Send initial data to client // New Minute NewMinuteOutgoingMessage msgNewMinute = (NewMinuteOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.NEW_MINUTE); msgNewMinute.MinuteOfTheDay = calendar.MinuteOfTheDay; pc.PutMessageIntoMyQueue(msgNewMinute); // You Are YouAreOutgoingMessage msgYouAre = (YouAreOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.YOU_ARE); msgYouAre.EntityID = pc.EntityID; pc.PutMessageIntoMyQueue(msgYouAre); // Change Map pc.LocationChangeMapAtEnterWorld(); // Here Your Inventory HereYourInventoryOutgoingMessage msgHereYourInventory = (HereYourInventoryOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.HERE_YOUR_INVENTORY); pc.FillOutgoingMessage(msgHereYourInventory); pc.PutMessageIntoMyQueue(msgHereYourInventory); // Here Your Stats HereYourStatsOutgoingMessage msgHereYourStats = (HereYourStatsOutgoingMessage)OutgoingMessagesFactory.Create(OutgoingMessageType.HERE_YOUR_STATS); pc.FillOutgoingMessage(msgHereYourStats); pc.PutMessageIntoMyQueue(msgHereYourStats); // Log In Ok pc.PutMessageIntoMyQueue(msgStdLogInOk); // All is OK pc.LoginState = PlayerCharacterLoginState.LoginSuccesfull; } }