Пример #1
0
        public void OnRenameSystem(object sender, SystemNameEventArgs e)
        {
            PlayerList pList = _gameData.PlayerList;

            //update playerlogs here for saving purposes
            for (int a = 0; a < pList.Count; a++)
            {
                pList[a].SystemLog[e.SysName.Index].Name = e.SysName.Name;
            }
            //signal players to update their logs
            for (int i = 0; i < 8; i++)
            {
                if (_clientHostArray[i] != null)
                {
                    _clientHostArray[i].SendSystemName(e.SysName);
                }
            }
        }
Пример #2
0
        private void ProcessMessage(byte [] data)
        {
            //Deserialize message
            IFormatter   fmt       = new BinaryFormatter();
            MemoryStream memHolder = new MemoryStream(data, 0, data.Length);

            memHolder.Position = 0;
            switch (_msgType)
            {
            case MsgType.Ping:
            {
                Console.WriteLine("Pong");
                break;
            }

            case MsgType.Text:
            {
                MsgText msg = (MsgText)fmt.Deserialize(memHolder);
                //if this is the first message assign it to client name
                if (_firstTime)
                {
                    _userName  = msg.Text;
                    _firstTime = false;
                    _connected = true;
                    if (eConnected != null)
                    {
                        EventArgs e = new EventArgs();
                        eConnected(this, e);
                    }
                }
                else if (eMessageReceived != null && _connected)
                {
                    //Else raise the MessageReceived Event
                    //and pass the message along
                    MessageEventArgs e = new MessageEventArgs(msg);
                    eMessageReceived(this, e);
                }
                break;
            }

            case MsgType.Orders:
            {
                //
                //	TODO: make sure it isn't possible to get more
                //     than one set of orders in the list for a
                //		single player
                //

                //accept fleet data from player and add to
                //arraylist of fleetdata
                if (_fleet != null && _orders.Contains(_fleet))
                {
                    Console.WriteLine("Old fleet orders removed for player " + this._clientID);
                    _orders.Remove(_fleet);
                }
                Console.WriteLine("Attempting to Deserialize Orders from player");
                this._fleet = (Fleet)fmt.Deserialize(memHolder);
                ClientHost._orders.Add(_fleet);
                Console.WriteLine("Fleet added to server orders");
                this._ready = true;
                if (eReady != null)
                {
                    EventArgs e = new EventArgs();
                    eReady(this, e);
                }
                break;
            }

            case MsgType.Cancel:
            {
                ClientHost._orders.Remove(this._fleet);
                Console.WriteLine("Fleet orders removed for player " + this._clientID);
                this._ready = false;
                break;
            }

            case MsgType.PlayerIDRequest:
            {
                NameAndID nameAndID = (NameAndID)fmt.Deserialize(memHolder);
                int       id        = nameAndID.ID;
                string    password  = nameAndID.Password;
                if (eIDRequest != null)
                {
                    Console.WriteLine(_userName + " requests player ID(event fired)");
                    IDRequestEventArgs e = new IDRequestEventArgs(id, password);
                    eIDRequest(this, e);
                }
                break;
            }

            case MsgType.SystemName:
            {
                MsgSystemName sysName = (MsgSystemName)fmt.Deserialize(memHolder);
                if (this.eRenameSystem != null)
                {
                    SystemNameEventArgs mea = new SystemNameEventArgs(sysName);
                    this.eRenameSystem(this, mea);
                }
                break;
            }

            case MsgType.Trade:
            {
                MsgTrade tradeMsg = (MsgTrade)fmt.Deserialize(memHolder);
                if (this.eTradeMessage != null)
                {
                    TradeMessageEventArgs ea = new TradeMessageEventArgs(tradeMsg);
                    this.eTradeMessage(this, ea);
                }
                break;
            }
            }
            memHolder.Close();
            //Determine message type
            //Carry out message instructions
        }