internal void OnWantCharList(CMSG_REQUESTCHARACTERLIST cpkt) { //HELPER VARIABLES ServerInfo2 info; LoginSession session; //CREATE CHARACTER-LIST if (LoginSessionHandler.sessions.TryGetValue(cpkt.SessionId, out session)) { if (ServerManager2.Instance.server.TryGetValue(session.World, out info)) { SMSG_CHARACTERLIST spkt = new SMSG_CHARACTERLIST(); spkt.Result = 0; spkt.CountAllServer = (byte)session.NCharacterCount; spkt.ServerName = info.name; spkt.SessionId = cpkt.SessionId; foreach (CharInfo info2 in session.list) { spkt.AddChar(info2.charId, info2.name, 1, info2.cexp, info2.job, 0, info2.map); } this.Send((byte[])spkt); } } }
public void CM_DELETE_CHARACTER(CMSG_INTERNAL_DELETIONREPLY cpkt) { ServerInfo2 info; LoginSession session; if (LoginSessionHandler.sessions.TryGetValue(cpkt.SessionId, out session)) { if (ServerManager2.Instance.server.TryGetValue(session.World, out info)) { Predicate <CharInfo> callback = delegate(CharInfo info2) { return(info2.charId == session.PedingCharDeletion); }; int index = session.list.FindIndex(callback); SMSG_DELETECHARACTER spkt = new SMSG_DELETECHARACTER(); spkt.SessionId = cpkt.SessionId; spkt.Index = (byte)index; //CHARACTER CREATION SUCCESS if (cpkt.Result == 0) { Singleton.Database.RemoveCharacterOnWorld(session.playerid, session.World); session.CachedCharacterStates.Remove(session.PedingCharDeletion); if (index > -1) { session.list.RemoveAt(index); } session.PedingCharDeletion = 0; session.client.Send((byte[])spkt); SMSG_CHARACTERLIST spkt2 = new SMSG_CHARACTERLIST(); spkt2.Result = 0; spkt2.CountAllServer = (byte)--session.NCharacterCount; spkt2.ServerName = info.name; spkt2.SessionId = cpkt.SessionId; foreach (CharInfo info2 in session.list) { spkt2.AddChar(info2.charId, info2.name, 1, info2.cexp, info2.job, 0, info2.map); } session.client.Send((byte[])spkt2); } else { session.PedingCharDeletion = 0; spkt.Result = cpkt.Result; session.client.Send((byte[])spkt); } } } }
private void OnSelectServer(CMSG_SELECTSERVER cpkt) { //HELPER VARIABLES ServerInfo2 info; LoginSession session; //TRY TO ESTABLISH A CONNECTION TO OUR BACKEND if (LoginSessionHandler.sessions.TryGetValue(cpkt.SessionId, out session)) { if (ServerManager2.Instance.server.TryGetValue(cpkt.Index, out info)) { //CHECK IF CLIENT IS NULL if (info.client == null) { SMSG_CHARACTERLIST spkt = new SMSG_CHARACTERLIST(); spkt.Result = (byte)LoginError.NO_ERROR_NO_SERVER_LIST; spkt.SessionId = cpkt.SessionId; this.Send((byte[])spkt); } //CHECK IF PLAYER IS TOO YOUNG else if (session.Age < info.RequiredAge) { SMSG_CHARACTERLIST spkt = new SMSG_CHARACTERLIST(); spkt.Result = (byte)LoginError.TOO_YOUNG_TOPLAY; spkt.SessionId = cpkt.SessionId; this.Send((byte[])spkt); } //EVERYTHING OKAY else { session.IsWaiting = true; session.World = cpkt.Index; info.client.SM_SELECT_CHARACTERS(session.playerid, cpkt.SessionId); bool Timedout = false; int LastTick = Environment.TickCount; Trace.TraceError("Start waiting for character list"); while (session.IsWaiting) { if (Environment.TickCount - LastTick > 20000) { Timedout = true; session.IsWaiting = false; break; } else { Thread.Sleep(0); } } if (!Timedout) { Trace.TraceError("Received successfull awner after {0}ms", Environment.TickCount - LastTick); CMSG_REQUESTCHARACTERLIST cpkt2 = new CMSG_REQUESTCHARACTERLIST(); cpkt2.SessionId = cpkt.SessionId; OnWantCharList(cpkt2); } else { Trace.TraceError("Login server timed out: {0}ms", Environment.TickCount - LastTick); SMSG_CHARACTERLIST spkt = new SMSG_CHARACTERLIST(); spkt.Result = (byte)LoginError.UNIDENTIFIED_LOGIN_ERROR; spkt.SessionId = cpkt.SessionId; this.Send((byte[])spkt); } } } else { SMSG_CHARACTERLIST spkt = new SMSG_CHARACTERLIST(); spkt.Result = (byte)LoginError.INCORRECT_KEY_OR_SERVERNUMBERVALUE; spkt.SessionId = cpkt.SessionId; this.Send((byte[])spkt); } } }