Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
 private void Listener_PeerConnectedEvent(NetPeer peer)
 {
     peer.Tag = SocketMan.CreatePlayer();
 }