Beispiel #1
0
        /*~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~数据库~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~*/
        private void OnDBPageClick(object sender, EventArgs e)
        {
            if (m_tabDB_Start.Text == "停止")
            {
                m_tabDB_Start.Enabled = false;
                ClientNetManager.Instance.CloseAll();
                m_tabDB_Start.Text    = "开始";
                m_tabDB_Start.Enabled = true;
                EnableTabPage(true, m_tabDB);
                EnableDBTabPage(true);

                EventController.TriggerEvent(ClientEventID.SWITCH_PRESSURE, ePressureType.DB, false);
            }
            else
            {
                sPressureDBInfo info = new sPressureDBInfo();
                info.ip            = this.m_tabDB_IP.Text;
                info.port          = ushort.Parse(this.m_tabDB_Port.Text);
                info.client_count  = ushort.Parse(this.m_tabDB_ClientCount.Text);
                info.start_account = int.Parse(this.m_tabDB_StartAccount.Text);
                info.end_account   = long.Parse(this.m_tabDB_EndAccount.Text);
                info.dis_conn_time = float.Parse(this.m_tabDB_DisconTime.Text);
                ServerConfig.net_info.db_server_ip     = info.ip;
                ServerConfig.net_info.db_server_port   = info.port;
                ServerConfig.net_info.db_client_count  = info.client_count;
                ServerConfig.net_info.db_start_account = info.start_account;

                m_tabDB_Start.Enabled = false;
                EnableTabPage(false, m_tabDB);
                EnableDBTabPage(false);
                m_pressure_type    = ePressureType.DB;
                m_tabDB_Start.Text = "停止";

                EventController.TriggerEvent(ClientEventID.SWITCH_PRESSURE, ePressureType.DB, true, info);
                ClientNetManager.Instance.StartConnect(info.ip, info.port, info.client_count, 8);
                m_tabDB_Start.Enabled = true;
            }
        }
        private void OnGameEvent(GameEvent evt)
        {
            switch (evt.type)
            {
            case ClientEventID.NET_CONNECTED_OPEN:
            {
                if (!m_active)
                {
                    break;
                }
                long conn_idx = evt.Get <long>(0);
                if (!m_connectes.ContainsKey(conn_idx))
                {
                    if (m_dis_connectes.Count > 0)
                    {
                        DBClient client = MathUtils.RandRange_List <DBClient>(m_dis_connectes);
                        client.ReSetup(conn_idx);
                        m_connectes.Add(conn_idx, client);
                        m_dis_connectes.Remove(client);
                    }
                    else
                    {
                        DBClient client = new DBClient();
                        client.Setup(conn_idx, m_pressure_info.start_account, conn_idx);
                        m_connectes.Add(conn_idx, client);
                    }
                }
            }
            break;

            case ClientEventID.NET_CONNECTED_CLOSE:
            {
                if (!m_active)
                {
                    break;
                }
                long     conn_idx = evt.Get <long>(0);
                DBClient client;
                if (m_connectes.TryGetValue(conn_idx, out client))
                {
                    m_dis_connectes.Add(client);
                }
                m_connectes.Remove(conn_idx);
            }
            break;

            case ClientEventID.SWITCH_PRESSURE:
            {
                ePressureType type     = evt.Get <ePressureType>(0);
                bool          is_start = evt.Get <bool>(1);
                if (type == ePressureType.DB && is_start)
                {
                    m_pressure_info = evt.Get <sPressureDBInfo>(2);
                    this.Start();
                }
                else
                {
                    this.Stop();
                }
            }
            break;

            case ClientEventID.RECV_DATA:
            {
                if (!m_active)
                {
                    break;
                }
                long      conn_idx = evt.Get <long>(0);
                ushort    header   = evt.Get <ushort>(1);
                ByteArray data     = evt.Get <ByteArray>(2);
                DBClient  client;
                if (m_connectes.TryGetValue(conn_idx, out client))
                {
                    client.OnNetworkServer(header, data);
                }
            }
            break;
            }
        }