예제 #1
0
        private void Send(int reqId, int resId, byte[] content, Action <int, ProtoPacket> callback)
        {
            //todo check network

            if (resId != 0)
            {
                //previous req is override, notify error
                if (mIdToOnceHandler.TryGetValue(resId, out var delegateObj))
                {
                    var error = ProtoPacket.CreateError(resId, (int)ErrorCode.req_override, string.Empty);
                    if (delegateObj != null)
                    {
                        delegateObj.DynamicInvoke(resId, error);
                    }
                    mIdToOnceHandler.Remove(resId);
                }

                if (callback != null)
                {
                    AddToHandler(resId, callback, mIdToOnceHandler);
                }

                var reqRecord = new ReqRecord();
                reqRecord.reqId   = reqId;
                reqRecord.resId   = resId;
                reqRecord.reqTime = Time.realtimeSinceStartup;
                mIdToRecord.Add(resId, reqRecord);
            }

            mChannel.Send(SendBuf.From(DCGameProtocol.GetIntBuf(reqId)), SendBuf.From(content));
        }
예제 #2
0
    /// <summary>
    /// 初始化socket并连接
    /// </summary>
    /// <param name="ipStr">IP</param>
    /// <param name="port">端口</param>
    public bool Init(string ipStr, int port)
    {
        System.Random rand = new System.Random();
        m_msgId   = rand.Next(10000, 20000); // rand start msg id
        m_running = true;
        m_ip      = ipStr;
        m_port    = port;

        m_recvQueue = new ConcurrentQueue <ProtoPacket>();
        m_sendQueue = new ConcurrentQueue <ProtoPacket>();

        Task taskConnect = Task.Factory.StartNew(() =>
        {
            if (!ConnectServer())
            {
                // 重连展示
                AddReconnect();

                return(false);
            }
            else
            {
                ProtoPacket reconnectPacket = new ProtoPacket();
                reconnectPacket.cmdId       = Constants.Reconnect;
                reconnectPacket.msgId       = 2; // 重连成功
                m_recvQueue.Enqueue(reconnectPacket);

                return(true);
            }
        });

        return(true);
    }
예제 #3
0
 public void Dispatch(ClientHandler clientHandler, int id, ProtoPacket packet)
 {
     DCLog.LogEx("handle req ", id);
     if (mIdToDelegates.TryGetValue(id, out var handler))
     {
         handler.DynamicInvoke(clientHandler, id, packet);
     }
 }
예제 #4
0
        public void OnMsg(Packet packet)
        {
            //首次连接第一个协议必须是user token

            var protoPacket = ProtoPacket.FromRecvBuf(packet.Bytes, 0, packet.Length);
            var id          = protoPacket.protoId;

            ReqDispatcher.Instance.Dispatch(this, id, protoPacket);
        }
예제 #5
0
 private void Invoke(int id, ProtoPacket packet, Dictionary <int, Delegate> dic)
 {
     if (dic.TryGetValue(id, out var delegateObj))
     {
         if (delegateObj != null)
         {
             delegateObj.DynamicInvoke(id, packet);
         }
     }
 }
예제 #6
0
        void OnPRoleEnterWorldNotify(int id, ProtoPacket proto)
        {
            //create role model and load scene
            var notify    = (PRoleEnterWorldNotify)proto.ProtoObj;
            var actorInfo = notify.PlayerActor;

            var actorSys = SysBoxP.ActorSysP;
            var actor    = actorSys.CreateActor(actorInfo);

            actorSys.Add(actor.GetActorGId(), actor);
        }
예제 #7
0
        public static ProtoPacket FromRecvBuf(byte[] buf, int off, int len)
        {
            var packet = new ProtoPacket();

            packet.len     = DCGameProtocol.GetUshort(buf, off);
            packet.protoId = DCGameProtocol.GetInt(buf, off + 2);
            packet.buf     = buf;
            packet.offset  = off + 2 + 4;
            //len = (protoIdBytesLength + protoContentBytesLength)
            packet.protoLen = len - 4;
            return(packet);
        }
예제 #8
0
        void OnAddRoleRes(int id, ProtoPacket proto)
        {
            //yeah , let's go to the game world
            DCLog.Log("yeah , let's go to the game world!");
            Close();

            MsgSys.Send(PlayerEvt.close_select_role_ui);

            var sceneId = ParamsCfgMgr.Instance.GetInt((int)PParamsConfig.BeginnerScene);

            LoadScene(sceneId);
        }
예제 #9
0
        public void HandleLoginSvrReq(ClientHandler clientHandler, int id, ProtoPacket packet)
        {
            var loginSvrReq = (PLoginSvrReq)packet.ProtoObj;
            var role        = PlayerDB.Instance.GetRole(loginSvrReq.RoleId);

            clientHandler.Role = role;
            var loginSvrRes = new PLoginSvrRes();

            clientHandler.Send(loginSvrRes);

            NotifyRoleEnterWorld(clientHandler);
        }
예제 #10
0
    void AddReconnect()
    {
        if (m_rcElapse > 0)
        {
            return;
        }

        ProtoPacket reconnectPacket = new ProtoPacket();

        reconnectPacket.cmdId = Constants.Reconnect;
        reconnectPacket.msgId = 1; // 外部重连
        m_recvQueue.Enqueue(reconnectPacket);
    }
예제 #11
0
        private void OnRoleRes(int id, ProtoPacket protoPkt)
        {
            if (DCGameProtocol.CheckError(id, protoPkt) != ErrorCode.UNIVERSAL)
            {
                var errorRes = protoPkt.GetError();
                DCLog.LogEx(errorRes.No, errorRes.OpCode, errorRes.Msg);
                return;
            }

            var roleRes = (PRoleRes)protoPkt.ProtoObj;

            mRoleList.Clear();
            mRoleList.AddRange(roleRes.Infos);
        }
예제 #12
0
        public static ProtoPacket CreateError(int id, int no, PTxtOp op, string msg)
        {
            var packet = new ProtoPacket();

            packet.protoId = id;

            var errorRes = new PErrorRes();

            errorRes.No     = no;
            errorRes.Msg    = msg;
            errorRes.OpCode = op;

            packet.protoObj = errorRes;

            return(packet);
        }
예제 #13
0
        public void OnReceive(Packet packet)
        {
            var protoPacket = ProtoPacket.FromRecvBuf(packet.Bytes, 0, packet.Length);
            var id          = protoPacket.protoId;

            DCLog.LogEx("receive protoId ", id);
            if (id > 0)
            {
                mIdToRecord.Remove(id);

                //长期监听的先执行
                Invoke(id, protoPacket, mIdToNormalHandler);

                Invoke(id, protoPacket, mIdToOnceHandler);
                mIdToOnceHandler.Remove(id);
            }
        }
예제 #14
0
    /// <summary>
    /// 向发送数据队列添加数据
    /// </summary>
    /// <param name="cmdId">命令号</param>
    /// <param name="msgId">消息号</param>
    /// <param name="obj">proto</param>
    public void SendEnqueue(int cmdId, int msgId, object obj, WorkDone cb = null)
    {
        // 检查回调函数列表
        if (cb != null)
        {
            m_callbackDict.Add(m_msgId, cb);
            m_callBackElapse.Add(m_msgId, System.DateTime.Now.Second);
        }

        ProtoPacket packet = new ProtoPacket();

        packet.cmdId = cmdId;
        packet.msgId = m_msgId++;
        packet.proto = obj;

        DebugConsole.Log("m_sendQueue enqueue:cmd=" + cmdId.ToString() + ", msgid=" + packet.msgId.ToString());
        m_sendQueue.Enqueue(packet);
    }
예제 #15
0
        public void OnMsg(Packet packet)
        {
            //首次连接第一个协议必须是user token

            var protoPacket = ProtoPacket.FromRecvBuf(packet.Bytes, 0, packet.Length);

            if (protoPacket.ProtoObj is PTestDemoClsReq req)
            {
                var f1 = req.F1;
                if (f1 == null)
                {
                    DCLog.Log("default is null");
                }
            }

            //echo to client
            mChannel.Send(
                SendBuf.From(Encoding.UTF8.GetBytes("echo ")),
                SendBuf.From(packet.Bytes, 0, packet.Length));
        }
예제 #16
0
        public void HandleAddRoleReq(ClientHandler clientHandler, int id, ProtoPacket packet)
        {
            var roleReq = (PAddRoleReq)packet.ProtoObj;
            var role    = PlayerDB.Instance.AddRole(clientHandler.User.ID, (int)roleReq.Job, roleReq.Name);
            //equip

            //actor data
            var actorData       = new PActorData();
            var jobConfigDefine = JobCfgMgr.Instance.Get(role.job_type, role.level);

            actorData.Hp = jobConfigDefine.MaxHp;
            actorData.Hp = jobConfigDefine.MaxMp;
            //task

            clientHandler.Role = role;
            var addRoleRes = new PAddRoleRes();

            clientHandler.Send(addRoleRes);

            NotifyRoleEnterWorld(clientHandler);
        }
예제 #17
0
        public void HandleRoleReq(ClientHandler clientHandler, int id, ProtoPacket packet)
        {
            var roleReq = (PRoleReq)packet.ProtoObj;

            clientHandler.User = CheckUser(roleReq.UserToken);

            var roles = PlayerDB.Instance.GetRoles(clientHandler.User.ID);
            var res   = new PRoleRes();

            foreach (var role in roles)
            {
                res.Infos.Add(new PRoleInfo()
                {
                    Job    = (PJobType)role.job_type,
                    Level  = role.level,
                    Name   = role.name,
                    RoleId = role.id,
                });
            }
            clientHandler.Send(res);
        }
예제 #18
0
 private void timer_0_Elapsed(object sender, ElapsedEventArgs e)
 {
     if (Interlocked.Exchange(ref int_0, 1) == 0)
     {
         try
         {
             if (bool_1)
             {
                 Send(new byte[14]
                 {
                     14,
                     0,
                     0,
                     0,
                     4,
                     30,
                     12,
                     0,
                     200,
                     0,
                     0,
                     0,
                     0,
                     0
                 });
             }
             else
             {
                 Send(ProtoPacket.pack(new PCS_APPing()));
             }
         }
         catch
         {
         }
         finally
         {
             Interlocked.Exchange(ref int_0, 0);
         }
     }
 }
예제 #19
0
    /// <summary>
    /// 解析二进制包,并入队列
    /// </summary>
    /// <param name="Head">包头</param>
    /// <param name="Head">包尾</param>
    public void UnPack(byte[] Head, byte[] Body)
    {
        try
        {
            byte[] cmd = new byte[4];
            Array.Copy(Head, 4, cmd, 0, 4);
            int cmdId = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(cmd, 0));

            byte[] msg = new byte[4];
            Array.Copy(Head, 8, msg, 0, 4);
            int msgId = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(msg, 0));

            ProtoPacket packet = new ProtoPacket();
            packet.cmdId = cmdId;
            packet.msgId = msgId;

            // 检查回调函数列表
            if (m_callbackDict.ContainsKey(msgId))
            {
                packet.callback = m_callbackDict[msgId];
                m_callbackDict.Remove(msgId);
            }

            // 检查回调超时
            int        secCur  = System.DateTime.Now.Second;
            List <int> delList = new List <int>();
            foreach (var item in m_callBackElapse)
            {
                int sec = item.Value;
                if (secCur - sec > 300)
                {
                    delList.Add(item.Key);
                }
            }

            for (int i = 0; i < delList.Count; ++i)
            {
                int key = delList[i];
                DebugConsole.Log("Delete time out callback");
                m_callbackDict.Remove(key);
                m_callBackElapse.Remove(key);
            }

            if (!m_types.ContainsKey(cmdId))
            {
                DebugConsole.Log("Not supported cmdId:" + cmdId + " in ProtoNet:" + m_name);
            }
            else
            {
                //MemoryStream ms = new MemoryStream(Body, 0, Body.Length);
                //Type type = m_types[cmdId];
                //object obj = new PBMessageSerializer().Deserialize(ms, null, type);
                object obj = m_types[cmdId].ParseFrom(Body, 0, Body.Length);
                if (obj == null)
                {
                    DebugConsole.Log("Deserialize error for cmdId:" + cmdId + " in ProtoNet:" + m_name);
                }
                else
                {
                    packet.proto = obj;
                    m_recvQueue.Enqueue(packet);
                }
            }

            /*
             * switch (cmdId)
             * {
             *  case SlotClientConstants.Server_UserInfo:
             *      {
             *          MemoryStream ms = new MemoryStream(Body, 0, Body.Length);
             *          UserInfo usrInfo
             *              = new PBMessageSerializer().Deserialize(ms, null, typeof(UserInfo)) as UserInfo;
             *
             *          if (usrInfo != null)
             *          {
             *              packet.proto = usrInfo;
             *              m_recvQueue.Enqueue(packet);
             *          }
             *      }
             *      break;
             *  case SlotClientConstants.Server_TigerResp:
             *      {
             *          MemoryStream ms = new MemoryStream(Body, 0, Body.Length);
             *          TigerResp tigerResp
             *              = new PBMessageSerializer().Deserialize(ms, null, typeof(TigerResp)) as TigerResp;
             *
             *          if (tigerResp != null)
             *          {
             *              packet.proto = tigerResp;
             *              m_recvQueue.Enqueue(packet);
             *          }
             *      }
             *      break;
             *  case SlotClientConstants.Server_LoginResp:
             *      {
             *          MemoryStream ms = new MemoryStream(Body, 0, Body.Length);
             *          LoginResp loginResp
             *              = new PBMessageSerializer().Deserialize(ms, null, typeof(LoginResp)) as LoginResp;
             *
             *          if (loginResp != null)
             *          {
             *              packet.proto = loginResp;
             *              m_recvQueue.Enqueue(packet);
             *          }
             *      }
             *      break;
             *  case SlotClientConstants.Server_RedirectResp:
             *      {
             *          MemoryStream ms = new MemoryStream(Body, 0, Body.Length);
             *          RedirectResp rdResp
             *              = new PBMessageSerializer().Deserialize(ms, null, typeof(RedirectResp)) as RedirectResp;
             *
             *          if (rdResp != null)
             *          {
             *              packet.proto = rdResp;
             *              m_recvQueue.Enqueue(packet);
             *          }
             *      }
             *      break;
             *  case SlotClientConstants.Server_Error:
             *      {
             *
             *      }
             *      break;
             *  default:
             *      WriteLog("Unknown cmd");
             *      break;
             * }*/
        }
        catch (Exception e)
        {
            WriteLog("UnPack Error:" + e.ToString());
        }
    }
예제 #20
0
 /// <summary>
 /// Verifies if the filter matches the specified packet.
 /// </summary>
 /// <param name="packet">The packet.</param>
 /// <returns><b>True</b> if the packet matches the filter, <b>false</b> otherwise.</returns>
 public abstract bool Matches(ProtoPacket packet);
예제 #21
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyUp(KeyCode.Escape))
        {
            if (DialogBase.Actived())
            {
                DebugConsole.Log("Hide");
                DialogBase.Hide();
            }
            else
            {
                DebugConsole.Log("Show");
                DialogBase.Show("ESC", "Are you sure to exit game?", QuitGame);
            }
        }

        if (m_broadcastMsg != "")
        {
            // 有系统消息,平移吧
            GameObject goBroadcast = GameObject.Find("BroadcastText");
            Vector3    pos         = goBroadcast.transform.localPosition;
            pos.x -= 50 * Time.deltaTime;
            goBroadcast.transform.localPosition = pos;

            // 从600~-600
            if (goBroadcast.transform.localPosition.x < -600)
            {
                m_broadcastMsg = "";
            }
        }
        else
        {
            m_broadcastMsg = Lobby.getInstance().GetBroadcast();
            if (m_broadcastMsg != "")
            {
                GameObject goBroadcast = GameObject.Find("BroadcastText");
                goBroadcast.GetComponent <Text>().text = m_broadcastMsg;
                goBroadcast.transform.localPosition    = new Vector3(600, 0, 0);
            }
        }

        if (m_net == null || !m_net.IsRunning())
        {
            // 主动结束了
            return;
        }

        if (m_net.CheckReconnect())
        {
            CheckLogin();

            DialogReconnect.Hide();
        }

        ProtoPacket packet = new ProtoPacket();

        if (m_net.RecvTryDequeue(ref packet))
        {
            DebugConsole.Log("Reception handle cmdId:" + packet.cmdId);
            switch (packet.cmdId)
            {
            case Constants.Lion_QuickLoginInfo:
            {
                Lobby.getInstance().UserInfo = (LionUserInfo)packet.proto; // 更新LionUser
                m_login = true;
                UpdateUserInfoUI();                                        // 更新大厅主界面中信息
                if (packet.callback != null)
                {
                    packet.callback();
                }
            }
            break;

            case Constants.Lion_GetProfile:
            {
                LionUserInfo usrInfo = (LionUserInfo)packet.proto;        // 更新LionUser
                if (usrInfo.UserId == Lobby.getInstance().UId)
                {
                    Lobby.getInstance().UserInfo = usrInfo;
                }
                Lobby.getInstance().QueryUserInfo = usrInfo;

                if (packet.callback != null)
                {
                    // 通常这里显示个人信息对话框
                    packet.callback();
                }
            }
            break;

            case Constants.Lion_GetTigerStat:
            {
                Lobby.getInstance().TigerStatInfo = (TigerStat)packet.proto;
                if (packet.callback != null)
                {
                    packet.callback();
                }
            }
            break;

            case Constants.Lion_GetFriendRequests:
            case Constants.Lion_GetFriends:
            {
                Lobby.getInstance().FriendIDArray = (LongArray)packet.proto;
                if (packet.callback != null)
                {
                    GetFriendSummary(packet.callback);
                }
                else
                {
                    GetFriendSummary(ShowFriendsDlg);
                }
            }
            break;

            case Constants.Lion_GetFriendSummary:
            {
                Lobby.getInstance().CurrentSummaryList = (FriendSummaryList)packet.proto;
                DebugConsole.Log("Summary count:" + Lobby.getInstance().CurrentSummaryList.Data.Count);
                if (packet.callback != null)
                {
                    packet.callback();
                }
            }
            break;

            case Constants.Lion_IgnoreFriend:
            case Constants.Lion_AcceptFriend:
            case Constants.Lion_AddFriend:
            case Constants.Lion_DeleteFriend:
            {
                Status stat = (Status)packet.proto;
                if (stat.Code == 0)        // successful
                {
                    if (packet.callback != null)
                    {
                        packet.callback();
                    }
                }
                else
                {
                    DebugConsole.Log(stat.Desc);
                }
            }
            break;

            case Constants.Lion_Redirect:
            {
                Lobby.getInstance().RedirectInfo = (RedirectResp)packet.proto;
                // 切换到游戏场景中
                //m_net.Close();
                DebugConsole.Log("Reception enter slot scene");
                Global.NextSceneName = "slot";
                SceneManager.LoadScene("loading");
            }
            break;

            case Constants.Lion_UpdateProfile:
            {
                DebugConsole.Log("Lion_UpdateProfile");
                Status stat = (Status)packet.proto;
                if (stat.Code == 0)        // successful
                {
                    if (packet.callback != null)
                    {
                        packet.callback();
                    }
                }
                else
                {
                    DebugConsole.Log(stat.Desc);
                }
            }
            break;

            case Constants.Lion_NotifyWeeklyLogin:
            {
                // 连续登录奖励
                // NotifyWeeklyLogin 返回的intvalue是0-6,0表示今天登陆了(昨天没登录)
                IntValue iv = (IntValue)packet.proto;
                DialogDailyBonus.Show(iv.Value);

                //ExplodeCoin.Show();
            }
            break;

            case Constants.Lion_TakeLoginBonus:
            {
                LongArray la = (LongArray)packet.proto;
                // la[0] 奖励金币数
                // la[1] 最终总数
                if (la.Data.Count >= 2)
                {
                    Lobby.getInstance().UserInfo.Gold = la.Data[1];
                    // 若有动画,在此添加
                    JumpAndMoveCoins(6, UpdateUserInfoUI);
                }
            }
            break;

            case Constants.Lion_NotifyFreeBonus:
            {
                // 第一次登陆的时候,数据库里面没有数据,所以返回0
                // 后端推送,倒计时剩余时间长度(毫秒),如果小于等于0,直接显示奖励
                // 免费奖励
                LongValue lv       = (LongValue)packet.proto;
                long      curEpoch = (System.DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000;
                Lobby.getInstance().FreeBonusEpoch = curEpoch + lv.Value;
                UpdateCountDown();
            }
            break;

            case Constants.Lion_TakeFreeBonus:
            {
                LongArray la = (LongArray)packet.proto;
                if (la.Data.Count >= 2)
                {
                    Lobby.getInstance().UserInfo.Gold = la.Data[1];
                    // 若有动画,在此添加
                    FlyCoin(Constants.Bonus_Free);
                    UpdateUserInfoUI();
                }
            }
            break;

            case Constants.Lion_BuyItem:
            {
                Status stat = (Status)packet.proto;
                // 更新购买相关的:金币 or 背包
                DebugConsole.Log("Buy item return:" + stat.Code.ToString());
                if (stat.Code == 0)        // successful
                {
                    if (packet.callback != null)
                    {
                        packet.callback();
                    }
                }
                else
                {
                    DebugConsole.Log(stat.Desc);
                }
            }
            break;

            case Constants.Lion_Register:
            {
                Status stat = (Status)packet.proto;
                DebugConsole.Log("Register by email return:" + stat.Code.ToString());
                if (stat.Code == 0)        // successful
                {
                    if (packet.callback != null)
                    {
                        packet.callback();
                    }
                }
                else
                {
                    DebugConsole.Log(stat.Desc);
                    DialogBase.Show("Register by email", "Error:" + stat.Desc);
                }
            }
            break;

            case Constants.Lion_ModPass:
            {
                Status stat = (Status)packet.proto;
                DebugConsole.Log("Modify password return:" + stat.Code.ToString());
                if (stat.Code == 0)        // successful
                {
                    if (packet.callback != null)
                    {
                        packet.callback();
                    }
                }
                else
                {
                    DebugConsole.Log(stat.Desc);
                    DialogBase.Show("Modify password", "Error:" + stat.Desc);
                }
            }
            break;

            case Constants.Lion_RefreshGold:
            {
                LongValue lv = (LongValue)packet.proto;
                DebugConsole.Log("Refresh gold:" + lv.ToString());
                Lobby.getInstance().UserInfo.Gold = lv.Value;
                UpdateUserInfoUI();
            }
            break;

            case Constants.Lion_GetShopItems:
            {
                Lobby.getInstance().ShopList = (ShopList)packet.proto;
                DebugConsole.Log("ShopName:" + Lobby.getInstance().ShopList.ShopName);
                if (packet.callback != null)
                {
                    packet.callback();
                }
            }
            break;

            case Constants.Lion_BroadcastSystemMessage:
            {
                Tools.PlayNotification(Constants.Audio.Audio_Notification);
                StringValue sv = (StringValue)packet.proto;
                Lobby.getInstance().AddBroadcast(sv.Value);
            }
            break;

            case Constants.Lion_GetItems:
            {
                //
                Lobby.getInstance().UserItemList = (UserItemList)packet.proto;

                if (packet.callback != null)
                {
                    packet.callback();
                }
                else
                {
                    DialogBag.Show(null);
                }
            }
            break;

            case Constants.Reconnect:
            {
                // 展示重连对话框,直到重连成功
                if (packet.msgId == 1)
                {
                    ProtoNet.WriteLog("Reconnecting...");
                    // 3s后Display中重连
                    m_net.CheckReconnect(3);
                    DialogReconnect.Show();
                }
            }
            break;

            case Constants.Error:
            {
                // 展示错误
                Status stat = (Status)packet.proto;
                string err  = "Error:" + stat.Code.ToString() + "-" + stat.Desc;
                DialogBase.Show("ERROR", err);
            }
            break;

            default:
            {
                DebugConsole.Log("Reception invalid cmdId:" + packet.cmdId);
            }
            break;
            }
        }
    }
예제 #22
0
    // Update is called once per frame
    void Update()
    {
        if (DialogLogin.Actived())
        {
            return;
        }

        if (!m_net.IsRunning())
        {
            // 主动结束了
            return;
        }

        // Step
        m_net.CheckReconnect();
        //if (m_net.CheckReconnect())
        //{
        //DebugConsole.Log("Door:Reconnect successful.");
        //CheckLogin();

        //DialogBase.Hide();
        //}
        if (m_rcCount > 3)
        {
            DialogWarning.Show("No Network!",
                               "Your internet seems to be down.\nPlease check your network settings.",
                               "Retry",
                               "Exit",
                               OnOK,
                               OnCancel,
                               OnOK);
            return;
        }

        ProtoPacket packet = new ProtoPacket();

        if (m_net.RecvTryDequeue(ref packet))
        {
            DebugConsole.Log("Door:Reception handle cmdId:" + packet.cmdId);
            switch (packet.cmdId)
            {
            case Constants.Dog_Login:
            {
                LoginResp loginResp = (LoginResp)packet.proto;

                Lobby.getInstance().UId = loginResp.UserId;
                DebugConsole.Log("UId:" + loginResp.UserId);
                m_login = true;

                // 登录成功,重定向
                if (packet.callback != null)
                {
                    // 重定向
                    packet.callback();
                }
            }
            break;

            case Constants.Dog_Redirect:
            {
                RedirectResp rdResp = (RedirectResp)packet.proto;
                Lobby        lobby  = Lobby.getInstance();
                lobby.Domain = rdResp.Domain;
                lobby.Port   = rdResp.Port;
                lobby.Key    = rdResp.Key;

                m_net.Close();
                // 重定向到大厅
                DebugConsole.Log("Door:Redirect to lobby:" +
                                 lobby.Domain + ":" + lobby.Port);

                StartCoroutine(LoadingScene());
            }
            break;

            case Constants.Reconnect:
            {
                // 展示重连对话框,直到重连成功
                if (packet.msgId == 1)
                {
                    ProtoNet.WriteLog("Door:Reconnecting...");
                    // 3s后Display中重连
                    m_net.CheckReconnect(5);
                    //DialogBase.Show("RECONNECT", "reconnecting");
                    GameObject.Find("RcText").GetComponent <Text>().text = "Reconnecting...";
                    m_net.Ip = "182.92.74.240";
                    m_rcCount++;
                }
                else if (packet.msgId == 2)
                {
                    DebugConsole.Log("Door:Reconnect successful.");
                    //DialogBase.Hide();
                    GameObject.Find("RcText").GetComponent <Text>().text = "Connect successfully.";
                    // 启动默认登录
                    if (m_auto)
                    {
                        Login(Redirect);
                    }
                }
            }
            break;

            case Constants.Error:
            {
                // 这里一定是登录错误?
                Status stat = (Status)packet.proto;
                string err  = "Error:" + stat.Code.ToString() + "-" + stat.Desc;
                GameObject.Find("RcText").GetComponent <Text>().text = err;

                // 打开登录对话框
                DialogLogin.Show(LoginAsGuest, LoginWithFsID, null);
            }
            break;

            default:
            {
                DebugConsole.Log("Door:Invalid cmdId:" + packet.cmdId);
            }
            break;
            }
        }
        //process = (int)(async.progress * 100);
    }
예제 #23
0
        void OnAddRoleRes(int id, ProtoPacket proto)
        {
            var roleInfo = (PRoleInfo)proto.ProtoObj;

            mRoleList.Add(roleInfo);
        }
예제 #24
0
        void OnLoginSvrComplete(int id, ProtoPacket proto)
        {
            DCLog.Log("to game world");

            Close();
        }
예제 #25
0
 void OnLoginSvrRes(int id, ProtoPacket proto)
 {
 }
예제 #26
0
    public void Execute(ProtoPacket packet)
    {
        ProtoNet.WriteLog("handle cmd from server:" + packet.cmdId);
        switch (packet.cmdId)
        {
        case Constants.Tiger_QuickLoginInfo:    // QuickLoginInfo返回
        {
            TigerUserInfo usrInfo = (TigerUserInfo)packet.proto;

            /*
             * SlotClientNet.WriteLog("Recv proto packet[UserInfo]:\nid=" +
             *  usrInfo.user_id + "\ngold=" + usrInfo.gold);
             */
            UpdateUserInfo(usrInfo);
        }
        break;

        case Constants.Tiger_Spin:
        {
            TigerResp tigerResp = (TigerResp)packet.proto;

            /*
             * SlotClientNet.WriteLog("Recv proto packet[TigerResp]:\ntiger_no=" +
             *  tigerResp.tiger_no +
             *  "\nseq_no=" + tigerResp.seq_no +
             *  "\npos=" + tigerResp.pos.ToString() +
             *  "\nbonus=" + tigerResp.bonus +
             *  "\npos=" + tigerResp.pos);*/

            UpdateTigerResp(tigerResp);
        }
        break;

        case Constants.Reconnect:
        {
            if (packet.msgId == 1)
            {
                ProtoNet.WriteLog("Reconnecting...");
                // 3s后Display中重连
                m_clerk.Net.CheckReconnect(3);
            }
            else if (packet.msgId == 2)
            {
                ProtoNet.WriteLog("Reconnecting successfully.");
            }
            else
            {
                ProtoNet.WriteLog("Reconnecting successfully:" + packet.msgId);
            }
        }
        break;

        case Constants.Error:
        {
            ProtoNet.WriteLog("Reconnecting...");
        }
        break;

        default:
            ProtoNet.WriteLog("Unknown send cmd");
            break;
        }
    }
예제 #27
0
 private void timer_2_Elapsed(object sender, ElapsedEventArgs e)
 {
     if (Interlocked.Exchange(ref int_4, 1) == 0)
     {
         try
         {
             if (uid != 0 && sidnew != 0)
             {
                 try
                 {
                     List <uint> list = new List <uint>();
                     list.Add(uid);
                     PQueryUserInfoReq obj = new PQueryUserInfoReq
                     {
                         uidlist = list,
                         topSid  = sidnew,
                         type    = 0
                     };
                     byte[] serverName = bytetool.String2Bytes("channelUserInfo");
                     byte[] bytes      = default(byte[]);
                     using (ByteArray byteArray = new ByteArray(ProtoPacket.pack(obj)))
                     {
                         PContextField1 pContextField = new PContextField1();
                         pContextField.f1 = sidnew;
                         ProtoPacket protoPacket = ProtoPacket.unpack(byteArray.Buffer);
                         PAPRouter   pAPRouter   = new PAPRouter();
                         pAPRouter.m_objAPHdr.m_pAppUID                  = new CAppUID();
                         pAPRouter.m_objAPHdr.m_pAppUID.m_uAppID         = 259u;
                         pAPRouter.m_objAPHdr.m_pAppUID.m_uUID.low       = uid;
                         pAPRouter.m_objAPHdr.m_pRoutingKey              = new CRoutingKey();
                         pAPRouter.m_objAPHdr.m_pRoutingKey.m_uRealUri   = protoPacket.getUri();
                         pAPRouter.m_objAPHdr.m_pCompressionInfo         = new CCompressionInfo();
                         pAPRouter.m_objAPHdr.m_pClientInfo              = new CClientInfo();
                         pAPRouter.m_objAPHdr.m_pClientInfo.m_serverName = serverName;
                         pAPRouter.m_objAPHdr.m_pExtentProp              = new CExtentProp();
                         MYHashMap mapExtentProp = pAPRouter.m_objAPHdr.m_pExtentProp.m_mapExtentProp;
                         uint      num           = 1u;
                         mapExtentProp.put(num.ToString(), ProtoPacket.packNoHeader(pContextField));
                         MYHashMap mapExtentProp2 = pAPRouter.m_objAPHdr.m_pExtentProp.m_mapExtentProp;
                         num = 3u;
                         mapExtentProp2.put(num.ToString(), null);
                         pAPRouter.m_strLoad = protoPacket.getBuffer().Buffer;
                         pAPRouter.m_ururi   = protoPacket.getUri();
                         bytes = ProtoPacket.pack(pAPRouter);
                         byteArray.Dispose();
                     }
                     Send(bytes);
                 }
                 catch
                 {
                 }
             }
         }
         catch
         {
         }
         finally
         {
             Interlocked.Exchange(ref int_4, 0);
         }
     }
 }
예제 #28
0
 /// <summary>
 /// 从接收数据队列取数据
 /// </summary>
 /// <param name="packet">取出的包</param>
 /// <returns>返回成功与否</returns>
 public bool RecvTryDequeue(ref ProtoPacket packet)
 {
     return(m_recvQueue.TryDequeue(out packet));
 }
예제 #29
0
 /// <summary>
 /// 向发送数据队列添加数据
 /// </summary>
 /// <param name="packet">发出的包</param>
 public void SendEnqueue(ProtoPacket packet)
 {
     m_sendQueue.Enqueue(packet);
 }
예제 #30
0
    // Update is called once per frame
    void Update()
    {
        if (Input.GetKeyUp(KeyCode.Escape))
        {
            //这个地方可以写“再按一次退出”的提示
            if (DialogBase.Actived())
            {
                DebugConsole.Log("Hide in Clerk");
                DialogBase.Hide();
            }
            else
            {
                DebugConsole.Log("Show in Clerk");
                DialogBase.Show("ESC", "Exit game?", QuitGame);
            }
            //m_escapeTimes++;
            //StartCoroutine("resetTimes");
            //if (m_escapeTimes > 1)
            //{
            //    Application.Quit();
            //}
        }

        if (!m_net.IsRunning())
        {
            return;
        }

        if (m_net.CheckReconnect())
        {
            CheckLogin();
        }

        ProtoPacket packet = new ProtoPacket();

        if (m_net.RecvTryDequeue(ref packet))
        {
            m_displays.Execute(packet);
        }

        GameObject recp = GameObject.Find("Reception");

        if (recp == null)
        {
            if (m_broadcastMsg != "")
            {
                // 有系统消息,平移吧
                GameObject goBroadcast = GameObject.Find("BroadcastText");
                Vector3    pos         = goBroadcast.transform.localPosition;
                pos.x -= 50 * Time.deltaTime;
                goBroadcast.transform.localPosition = pos;

                // 从600~-600
                if (goBroadcast.transform.localPosition.x < -600)
                {
                    m_broadcastMsg = "";
                }
            }
            else
            {
                m_broadcastMsg = Lobby.getInstance().GetBroadcast();
                if (m_broadcastMsg != "")
                {
                    GameObject goBroadcast = GameObject.Find("BroadcastText");
                    goBroadcast.GetComponent <Text>().text = m_broadcastMsg;
                    goBroadcast.transform.localPosition    = new Vector3(600, 0, 0);
                }
            }

            // 不是Lobby,需要处理Reception消息
            // 如广播,以及store相关的
            ProtoNet net = Reception.Net();
            if (net != null)
            {
                packet = null;
                packet = new ProtoPacket();
                if (net.RecvTryDequeue(ref packet))
                {
                    switch (packet.cmdId)
                    {
                    case Constants.Lion_GetShopItems:
                    {
                        Lobby.getInstance().ShopList = (ShopList)packet.proto;
                        DebugConsole.Log("ShopName:" + Lobby.getInstance().ShopList.ShopName);
                        if (packet.callback != null)
                        {
                            packet.callback();
                        }
                    }
                    break;

                    case Constants.Lion_BroadcastSystemMessage:
                    {
                        Tools.PlayNotification(Constants.Audio.Audio_Notification);
                        StringValue sv = (StringValue)packet.proto;
                        Lobby.getInstance().AddBroadcast(sv.Value);
                    }
                    break;

                    default:
                        break;
                    }
                }
            }
        }
    }
예제 #31
0
 /// <summary>
 /// Verifies if the filter matches the specified packet.
 /// </summary>
 /// <param name="packet">The packet.</param>
 /// <returns><b>True</b> if the packet matches the filter, <b>false</b> otherwise.</returns>
 public override bool Matches(ProtoPacket packet)
 {
     if (!(packet is ProtoPacketIp)) return false;
     return this.Matches(packet as ProtoPacketIp);
 }