コード例 #1
0
        public override void Update()
        {
            base.Update();
            if (!_listen)
            {
                return;
            }
            List <NetIncomingMessage> msgs;

            LidgrenCommon.Listen(_client, Connection, _queue, _peers, out msgs);

            foreach (NetIncomingMessage msg in msgs)
            {
                if (msg.MessageType != NetIncomingMessageType.StatusChanged)
                {
                    continue;
                }
                NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte();
                if (status == NetConnectionStatus.Connected)
                {
                    ServerInfo info = new ServerInfo()
                    {
                        //Todo
                        ServerID   = new IPIdentity(0),
                        MaxPlayers = MAX_PLAYERS,
                        Name       = "A Lidgren Server",
                        Map        = "TestMap"
                    };
                    ((ClientConnection)Connection).Connect(info);
                }

                if (status == NetConnectionStatus.Disconnected)
                {
                    if (((ClientConnection)Connection).OnConnectionFailed())
                    {
                        continue;
                    }
                    LogUtils.Debug("Couldn't connect to host");
                    LevelManager.Instance.GoToMainMenu();
                    _listen = false;
                }
                _client.Recycle(msg);
            }
        }
コード例 #2
0
        public override void Update()
        {
            base.Update();
            if (!_listen)
            {
                return;
            }
            List <NetIncomingMessage> msgs;

            LidgrenCommon.Listen(_server, Connection, _queue, _peers, out msgs);
            foreach (NetIncomingMessage msg in msgs)
            {
                switch (msg.MessageType)
                {
                case NetIncomingMessageType.ConnectionApproval:
                    //Todo: check for password here?
                    msg.SenderConnection.Approve();
                    _server.Recycle(msg);
                    break;
                }
            }
        }
コード例 #3
0
 public override void CloseConnection(Identity user)
 {
     LidgrenCommon.CloseConnection(user, _peers);
 }
コード例 #4
0
 public override bool Write(Identity target, byte[] data, ulong length, SendMethod method, int channel)
 {
     return(LidgrenCommon.Write(target, data, length, method, channel, _server, _peers));
 }
コード例 #5
0
 public override bool Read(out Identity user, byte[] data, out ulong length, int channel)
 {
     return(LidgrenCommon.Read(out user, data, out length, channel, _queue));
 }