コード例 #1
0
        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);
                }
        }
コード例 #2
0
        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);
                }
        }