/// <summary> /// Adds a(n) <see cref="ISession"/>. /// </summary> /// <param name="addSession"></param> private void HandleAddSession(AddSession addSession) { ISession existingSession; // making sure we dont already have a session with the same session id if (sessions.TryGetValue(addSession.SessionId, out existingSession)) { // since adding sessions is controlled by the master rather than the client // we will not notify the client rather throw out an error Logger.ErrorFormat("[HandleAddSession]: Destroying existing Session (Name={0})", existingSession.Name); // destroy the exisiting session // we dont need to destroy the requested session since they both have the same session id, both (if possible) will be destroyed existingSession.Destroy(DestroySessionReason.KickedByExistingSession); return; } ISession session = new WorldSession(addSession.SessionId, addSession.CharacterName, this, world, addSession.IsTransfer); // if a lock wait time is used (not -1) use a while loop to counter lock timeouts if (!sessions.Add(addSession.SessionId, session)) { // this will not happen but Murphy's law states otherwise Logger.ErrorFormat("[HandleAddSession]: Session (Name={0}) cannot be added", addSession.CharacterName); session.Destroy(DestroySessionReason.KickedByServer); return; } // notifying the master to update the state so the client can start sending messages this.SendOperationRequest( new OperationRequest((byte)ServerOperationCode.AckClientPlayerTransferWorld, new AckClientPlayerEnterWorld { SessionId = session.SessionId, }), new SendParameters()); }