Ejemplo n.º 1
0
        private void DelegateOnTextMsgPushCallback(Object obj)
        {
            GmResponseMsg msg           = obj as GmResponseMsg;
            GmTextMsgPush gmTextMsgPush = GmTextMsgPush.ParseFrom(msg.ProtoData);

            AppendTextToConsole(gmTextMsgPush.Text);
        }
Ejemplo n.º 2
0
        private void DelegateOnGetAllServerStateCallback(Object obj)
        {
            GmResponseMsg msg = obj as GmResponseMsg;

            if (msg.ErrorCode == GmRpcErrorCodeEnum.GmRpcOk)
            {
                GmGetAllServerStateResponse resp = GmGetAllServerStateResponse.ParseFrom(msg.ProtoData);
                // logicServer
                lblLogicServerCount.Text = resp.LogicServerInfosCount.ToString();
                foreach (ServerLoadBalanceInfo info in resp.LogicServerInfosList)
                {
                    int addIndex = dgvLogicServerInfo.Rows.Add();
                    // ID
                    if (info.IsMainLogicServer == true)
                    {
                        dgvLogicServerInfo.Rows[addIndex].Cells[0].Value = info.Id + "(主)";
                    }
                    else
                    {
                        dgvLogicServerInfo.Rows[addIndex].Cells[0].Value = info.Id.ToString();
                    }
                    // IP
                    dgvLogicServerInfo.Rows[addIndex].Cells[1].Value = info.Ip;
                    // 负载
                    dgvLogicServerInfo.Rows[addIndex].Cells[2].Value = info.LoadBalance.ToString();
                }
                // battleServer
                lblBattleServerCount.Text = resp.BattleServerInfosCount.ToString();
                foreach (ServerLoadBalanceInfo info in resp.BattleServerInfosList)
                {
                    int addIndex = dgvBattleServerInfo.Rows.Add();
                    // ID
                    dgvBattleServerInfo.Rows[addIndex].Cells[0].Value = info.Id.ToString();
                    // IP
                    dgvBattleServerInfo.Rows[addIndex].Cells[1].Value = info.Ip;
                    // 负载
                    dgvBattleServerInfo.Rows[addIndex].Cells[2].Value = info.LoadBalance.ToString();
                }
                // gateway
                lblGatewayCount.Text = resp.GatewayInfosCount.ToString();
                foreach (ServerLoadBalanceInfo info in resp.GatewayInfosList)
                {
                    int addIndex = dgvGatewayInfo.Rows.Add();
                    // ID
                    dgvGatewayInfo.Rows[addIndex].Cells[0].Value = info.Id.ToString();
                    // IP
                    dgvGatewayInfo.Rows[addIndex].Cells[1].Value = info.Ip;
                    // 客户端连接地址
                    dgvGatewayInfo.Rows[addIndex].Cells[2].Value = info.GatewayConnectPath;
                    // 负载
                    dgvGatewayInfo.Rows[addIndex].Cells[3].Value = info.LoadBalance.ToString();
                }
            }
            else
            {
                string tips = string.Format("获取所有服务器状态失败,errorCode = {0}", msg.ErrorCode);
                MessageBox.Show(this, tips, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Ejemplo n.º 3
0
        private void DelegateOnExecuteCmdCallback(Object obj)
        {
            GmResponseMsg msg = obj as GmResponseMsg;

            if (msg.ErrorCode != GmRpcErrorCodeEnum.GmRpcOk)
            {
                string tips = string.Format("执行GM命令失败,errorCode = {0}", msg.ErrorCode);
                MessageBox.Show(this, tips, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Ejemplo n.º 4
0
        private void DelegateOnForceOfflinePushCallback(Object obj)
        {
            isReceivedForceOfflinePush = true;
            GmResponseMsg      msg = obj as GmResponseMsg;
            GmForceOfflinePush forceOfflinePush = GmForceOfflinePush.ParseFrom(msg.ProtoData);

            WebSocketManager.CloseWebSocket();
            string tips = string.Format("被GM服务器踢下线,原因为{0}\n请重新登录", forceOfflinePush.ForceOfflineReason);

            MessageBox.Show(this, tips, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            if (loginForm != null && loginForm.Visible == false)
            {
                loginForm.ShowDialog();
            }
        }
Ejemplo n.º 5
0
        private void DelegateOnGetOnlineUserInfoCallback(Object obj)
        {
            GmResponseMsg msg = obj as GmResponseMsg;

            if (msg.ErrorCode == GmRpcErrorCodeEnum.GmRpcOk)
            {
                GmGetOnlineUserInfoResponse resp = GmGetOnlineUserInfoResponse.ParseFrom(msg.ProtoData);
                OnlineUserInfoForm          form = new OnlineUserInfoForm(resp.OnlineUserInfosList);
                form.ShowDialog();
            }
            else
            {
                string tips = string.Format("获取在线玩家详情失败,errorCode = {0}", msg.ErrorCode);
                MessageBox.Show(this, tips, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Ejemplo n.º 6
0
        private void DelegateOnLoginCallback(Object obj)
        {
            GmResponseMsg msg = obj as GmResponseMsg;

            if (msg.ErrorCode == GmRpcErrorCodeEnum.GmRpcOk)
            {
                GmLoginResponse resp       = GmLoginResponse.ParseFrom(msg.ProtoData);
                GmUserInfo      gmUserInfo = resp.GmUserInfo;
                AppValues.GmUserInfo = gmUserInfo;
                this.Hide();
            }
            else
            {
                string tips = string.Format("登录失败,errorCode = {0}", msg.ErrorCode);
                MessageBox.Show(this, tips, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
        }
Ejemplo n.º 7
0
        private void OnExecuteCmdCallback(GmResponseMsg msg)
        {
            OperateUiDelegate delegateFunc = new OperateUiDelegate(DelegateOnExecuteCmdCallback);

            this.Invoke(delegateFunc, msg);
        }
Ejemplo n.º 8
0
        private void OnGetAllServerStateCallback(GmResponseMsg msg)
        {
            OperateUiDelegate delegateFunc = new OperateUiDelegate(DelegateOnGetAllServerStateCallback);

            this.Invoke(delegateFunc, msg);
        }
Ejemplo n.º 9
0
        private void OnGetOnlineUserInfoCallback(GmResponseMsg msg)
        {
            OperateUiDelegate delegateFunc = new OperateUiDelegate(DelegateOnGetOnlineUserInfoCallback);

            this.Invoke(delegateFunc, msg);
        }
Ejemplo n.º 10
0
        private void OnTextMsgPushCallback(GmResponseMsg msg)
        {
            OperateUiDelegate delegateFunc = new OperateUiDelegate(DelegateOnTextMsgPushCallback);

            this.Invoke(delegateFunc, msg);
        }
Ejemplo n.º 11
0
        public static void InitWebSocket()
        {
            if (ws != null)
            {
                ws.Close();
            }

            ws            = new WebSocket(AppValues.GM_SERVER_URL);
            ws.OnMessage += (sender, e) =>
            {
                if (e.IsBinary)
                {
                    GmResponseMsg msg       = new GmResponseMsg();
                    int           rpcNum    = IntEncodingUtil.ByteArrayToIntByBigEndian(e.RawData, 4);
                    GmRpcNameEnum gmRpcName = (GmRpcNameEnum)rpcNum;
                    msg.RpcName = gmRpcName;
                    int errorCode = IntEncodingUtil.ByteArrayToIntByBigEndian(e.RawData, 8);
                    GmRpcErrorCodeEnum gmRpcErrorCode = (GmRpcErrorCodeEnum)errorCode;
                    msg.ErrorCode = gmRpcErrorCode;
                    if (gmRpcErrorCode == GmRpcErrorCodeEnum.GmRpcOk)
                    {
                        int protoDataLength = e.RawData.Length - 12;
                        msg.ProtoData = new byte[protoDataLength];
                        Buffer.BlockCopy(e.RawData, 12, msg.ProtoData, 0, protoDataLength);
                    }
                    if (rpcHandlerDict.ContainsKey(gmRpcName))
                    {
                        rpcHandlerDict[gmRpcName](msg);
                    }
                }
                else
                {
                    Debug.WriteLine("收到非二进制数据");
                }
            };
            ws.OnOpen += (sender, e) =>
            {
                Debug.WriteLine("连接成功");
                // 开启定时心跳计时器,避免长时间空闲被GM服务器踢下线
                if (heartbeatTimer != null)
                {
                    heartbeatTimer.Close();
                    heartbeatTimer = null;
                }
                if (AppValues.HEARTBEAT_INTERVAL_MSEC > 0)
                {
                    heartbeatTimer           = new Timer(AppValues.HEARTBEAT_INTERVAL_MSEC);
                    heartbeatTimer.Elapsed  += new ElapsedEventHandler(OnHeartbeatTimer);
                    heartbeatTimer.AutoReset = true;
                    heartbeatTimer.Enabled   = true;
                }

                foreach (var hander in connectionOpenHandlerSet)
                {
                    hander(e);
                }
            };
            ws.OnError += (sender, e) =>
            {
                Debug.WriteLine("发生错误:" + e.Message);
                foreach (var hander in connectionErrorHandlerSet)
                {
                    hander(e);
                }
            };
            ws.OnClose += (sender, e) =>
            {
                Debug.WriteLine("连接关闭");
                if (heartbeatTimer != null)
                {
                    heartbeatTimer.Close();
                    heartbeatTimer = null;
                }

                foreach (var hander in connectionCloseHandlerSet)
                {
                    hander(e);
                }
            };

            ws.Connect();
        }