Пример #1
0
        private void Listener_PeerDisconnectedEvent(NetPeer peer, DisconnectInfo disconnectInfo)
        {
            var pl = peer.Tag as ServerPlayer;

            if (pl == null)
            {
                throw new Exception("ServerPlayer tag undefined on disconnect");
            }
            SocketMan.HandlePlayerDisconnected(pl.ClientIndex);
        }
Пример #2
0
        public override void StartSocket()
        {
            if (_socket != null)
            {
                StopSocket("Starting new socket");
            }

            _socket = SteamNetworkingSockets.CreateRelaySocket <SteamSocketInterface>();

            _socket._OnConnected = (connection, connectionInfo) =>
            {
                var pl = SocketMan.CreatePlayer();
                _steamidToClientIndex[connectionInfo.Identity.SteamId] = pl.ClientIndex;
            };

            _socket._OnConnecting = (connection, connectionInfo) =>
            {
                connection.Accept();
            };

            _socket._OnDisconnected = (connection, connectionInfo) =>
            {
                SocketMan.HandlePlayerDisconnected(GetClientIndex(connectionInfo.Identity.SteamId));
            };

            _socket._OnMessage = (connection, id, data, size, msgNum, recvTime, channel) =>
            {
                if (_recvBuffer.Data.Length < size)
                {
                    _recvBuffer.Data = new byte[size];
                }
                _recvBuffer.Position    = 0;
                _recvBuffer.LengthBytes = size;
                Marshal.Copy(data, _recvBuffer.Data, 0, size);
                SocketMan.HandleIncomingData2(GetClientIndex((SteamId)id), _recvBuffer);
            };

            SetSocketStatus(ServerStatus.AcceptingConnections);
        }