Exemple #1
0
        private void MainForm_Load(object sender, EventArgs e)
        {
            // 注册连接打开的响应函数
            WebSocketManager.AddConnectionOpenHandler(OnConnectionOpen);
            // 注册连接中断的响应函数
            WebSocketManager.AddConnectionCloseHandler(OnConnectionClose);
            // 注册连接错误的响应函数
            WebSocketManager.AddConnectionErrorHandler(OnConnectionError);

            // 注册一些服务器会主动push的消息
            WebSocketManager.AddRpcHandler(GmRpcNameEnum.GmRpcForceOfflinePush, OnForceOfflinePushCallback);
            WebSocketManager.AddRpcHandler(GmRpcNameEnum.GmRpcTextMsgPush, OnTextMsgPushCallback);

            // 与GM服务器建立连接
            WebSocketManager.InitWebSocket();
            if (WebSocketManager.IsConnected() == false)
            {
                string tips = string.Format("无法连接GM服务器,请确保服务器地址为{0},且处于开启状态", AppValues.GM_SERVER_URL);
                MessageBox.Show(this, tips, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
            }

            // 强制弹出登录界面
            loginForm = new LoginForm();
            loginForm.ShowDialog();
        }
Exemple #2
0
        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (WebSocketManager.IsConnected() == false)
            {
                WebSocketManager.InitWebSocket();
                if (WebSocketManager.IsConnected() == false)
                {
                    string tips = string.Format("无法连接GM服务器,请确保服务器地址为{0},且处于开启状态", AppValues.GM_SERVER_URL);
                    MessageBox.Show(this, tips, "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                    return;
                }
            }

            string inputUsername = txtUsername.Text.Trim();
            string inputPassword = txtPassword.Text.Trim();

            if (string.IsNullOrEmpty(inputUsername))
            {
                MessageBox.Show("用户名不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            if (string.IsNullOrEmpty(inputPassword))
            {
                MessageBox.Show("密码不能为空", "错误", MessageBoxButtons.OK, MessageBoxIcon.Error);
                return;
            }
            GmLoginRequest.Builder builder = GmLoginRequest.CreateBuilder();
            builder.SetUsername(inputUsername);
            MD5CryptoServiceProvider md5 = new MD5CryptoServiceProvider();
            string passwordMD5           = BitConverter.ToString(md5.ComputeHash(System.Text.Encoding.UTF8.GetBytes(inputPassword))).Replace("-", "").ToUpper();

            builder.SetPasswordMD5(passwordMD5);
            WebSocketManager.SendMessage(GmRpcNameEnum.GmRpcLogin, builder.Build().ToByteArray(), OnLoginCallback);
        }
Exemple #3
0
 private void MainForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     if (e.CloseReason == CloseReason.UserClosing)
     {
         isFormClosing = true;
         WebSocketManager.CloseWebSocket();
     }
 }
Exemple #4
0
 private void btnRefreshServerState_Click(object sender, EventArgs e)
 {
     dgvLogicServerInfo.Rows.Clear();
     dgvBattleServerInfo.Rows.Clear();
     dgvGatewayInfo.Rows.Clear();
     GmGetAllServerStateRequest.Builder builder = GmGetAllServerStateRequest.CreateBuilder();
     WebSocketManager.SendMessage(GmRpcNameEnum.GmRpcGetAllServerState, builder.Build().ToByteArray(), OnGetAllServerStateCallback);
 }
Exemple #5
0
 private void LoginForm_FormClosing(object sender, FormClosingEventArgs e)
 {
     // GM用户点击关闭登录窗口,会强制将整个软件关闭
     // 注意:当登录成功,执行LoginForm的Hide方法时,仍旧会触发LoginFrom的closing和closed方法
     // 如果不加上这个判断,就会因为LoginForm的Hide,执行下面的逻辑,导致WebSocket被关闭
     if (e.CloseReason == CloseReason.UserClosing)
     {
         WebSocketManager.CloseWebSocket();
         Environment.Exit(0);
     }
 }
Exemple #6
0
        private void btnGmServerCloseServer_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(this, "确定要关闭GM服务器吗?", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
            {
                return;
            }

            GmExecuteCmdRequest.Builder builder = GmExecuteCmdRequest.CreateBuilder();
            builder.SetServerType(RemoteServerTypeEnum.ServerTypeGm);
            builder.SetCmdType(GmCmdTypeEnum.GmCmdCloseServer);
            WebSocketManager.SendMessage(GmRpcNameEnum.GmRpcExecuteCmd, builder.Build().ToByteArray(), OnExecuteCmdCallback);
        }
Exemple #7
0
        private void btnBattleServerReloadTableConfig_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show(this, "确定要重载所有Battle服务器的表格吗?", "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
            {
                return;
            }

            GmExecuteCmdRequest.Builder builder = GmExecuteCmdRequest.CreateBuilder();
            builder.SetServerType(RemoteServerTypeEnum.ServerTypeBattle);
            builder.SetCmdType(GmCmdTypeEnum.GmCmdReloadTableConfig);
            WebSocketManager.SendMessage(GmRpcNameEnum.GmRpcExecuteCmd, builder.Build().ToByteArray(), OnExecuteCmdCallback);
        }
Exemple #8
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();
            }
        }
Exemple #9
0
        private void dgvLogicServerInfo_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                if (dgvLogicServerInfo.Columns[e.ColumnIndex].Name == "dgvcLogicServerReloadTableConfig" || dgvLogicServerInfo.Columns[e.ColumnIndex].Name == "dgvcLogicServerCloseServer")
                {
                    string idStr            = dgvLogicServerInfo.Rows[e.RowIndex].Cells[0].Value.ToString();
                    int    leftBracketIndex = idStr.IndexOf('(');
                    if (leftBracketIndex != -1)
                    {
                        idStr = idStr.Substring(0, leftBracketIndex);
                    }

                    int serverId = int.Parse(idStr);

                    GmExecuteCmdRequest.Builder builder = GmExecuteCmdRequest.CreateBuilder();
                    builder.SetServerType(RemoteServerTypeEnum.ServerTypeLogic);
                    builder.AddServerIds(serverId);

                    if (dgvLogicServerInfo.Columns[e.ColumnIndex].Name == "dgvcLogicServerReloadTableConfig")
                    {
                        string tips = string.Format("确定要重载id为{0}的Logic服务器表格吗?", serverId);
                        if (MessageBox.Show(this, tips, "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
                        {
                            return;
                        }

                        builder.SetCmdType(GmCmdTypeEnum.GmCmdReloadTableConfig);
                    }
                    else if (dgvLogicServerInfo.Columns[e.ColumnIndex].Name == "dgvcLogicServerCloseServer")
                    {
                        string tips = string.Format("确定要关闭id为{0}的Logic服务器吗?", serverId);
                        if (MessageBox.Show(this, tips, "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
                        {
                            return;
                        }

                        builder.SetCmdType(GmCmdTypeEnum.GmCmdCloseServer);
                    }

                    WebSocketManager.SendMessage(GmRpcNameEnum.GmRpcExecuteCmd, builder.Build().ToByteArray(), OnExecuteCmdCallback);
                }
            }
        }
Exemple #10
0
        private void dgvGatewayInfo_CellContentClick(object sender, DataGridViewCellEventArgs e)
        {
            if (e.RowIndex >= 0)
            {
                if (dgvGatewayInfo.Columns[e.ColumnIndex].Name == "dgvcGatewayCloseServer")
                {
                    string idStr    = dgvGatewayInfo.Rows[e.RowIndex].Cells[0].Value.ToString();
                    int    serverId = int.Parse(idStr);

                    string tips = string.Format("确定要关闭id为{0}的Gateway服务器吗?", serverId);
                    if (MessageBox.Show(this, tips, "警告", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning) != DialogResult.OK)
                    {
                        return;
                    }

                    GmExecuteCmdRequest.Builder builder = GmExecuteCmdRequest.CreateBuilder();
                    builder.SetServerType(RemoteServerTypeEnum.ServerTypeGateway);
                    builder.AddServerIds(serverId);
                    builder.SetCmdType(GmCmdTypeEnum.GmCmdCloseServer);

                    WebSocketManager.SendMessage(GmRpcNameEnum.GmRpcExecuteCmd, builder.Build().ToByteArray(), OnExecuteCmdCallback);
                }
            }
        }
Exemple #11
0
 private void btnGetOnlineUserInfo_Click(object sender, EventArgs e)
 {
     GmGetOnlineUserInfoRequest.Builder builder = GmGetOnlineUserInfoRequest.CreateBuilder();
     WebSocketManager.SendMessage(GmRpcNameEnum.GmRpcGetOnlineUserInfo, builder.Build().ToByteArray(), OnGetOnlineUserInfoCallback);
 }