public void RaisePacketReceived(ServerConnectionBase serverConnection)
        {
            var l = new LogInRequest {
                Email = "[email protected]", Password = "******"
            };
            var bp = BinaryProtocol.FromData(l, new ProtoBufGenericSerializer <LogInRequest>());

            _serverTransport.RaiseReceive(typeof(LogInRequest), bp.GetDataToSend(), serverConnection);
        }
示例#2
0
        public void RaiseReceive(Type comd, byte[] bytes, ServerConnectionBase serverConnection)
        {
            var conn  = serverConnection as ServerConnection <byte[]>;
            var proto = new BinaryProtocol(bytes);

            conn?.OnDataReceived(proto, new LogInRequest(), comd);
            OnReceive?.Invoke(this, new ServerGenericEventArgs <byte[]> {
                ServerConnectionBase = serverConnection, Protocol = new BinaryProtocol(bytes), DataReceived = bytes
            });
        }
示例#3
0
        public OperationState Send <T>(ServerConnectionBase serverConnectionBase, ProtocolBase <T> data)
        {
            var operationState = serverConnectionBase.ServerTransport.SendData(ConnectionId, data);

            if (operationState.IsSuccessful)
            {
                serverConnectionBase.TransportStats.AddBytesSent(operationState.Counter);
            }
            else
            {
                return(operationState);
            }
            return(new OperationState {
                IsSuccessful = true
            });
        }
示例#4
0
 protected void AddConnection(ServerConnectionBase serverConnectionBase)
 {
     if (serverConnectionBase == null)
     {
         throw new ArgumentNullException(nameof(serverConnectionBase));
     }
     serverConnectionBase.ServerTransport.ChangeConnectionId(serverConnectionBase.ConnectionId, ConnectionId);
     if (Connections.ContainsKey(serverConnectionBase.ServerTransport.TransportName))
     {
         var currentConnection = Connections[serverConnectionBase.ServerTransport.TransportName];
         currentConnection.CloseConnection();
         Connections.Remove(serverConnectionBase.ServerTransport.TransportName);
     }
     serverConnectionBase.Peer = this;
     Connections.Add(serverConnectionBase.ServerTransport.TransportName, serverConnectionBase);
 }
        private void GameServerPluginOnClientDisconnected(object sender, ServerConnectionBase connection)
        {
            var peersList = UsersInScenes.FirstOrDefault(x => x.Value.Contains(connection.Peer));

            if (!string.IsNullOrEmpty(peersList.Key))
            {
                peersList.Value?.Remove(connection.Peer);

                var leaveResponse = new LeaveResponse {
                    ConnectionId = connection.ConnectionId, IsOk = true
                };
                foreach (var peer in peersList.Value)
                {
                    var cmd = BinaryProtocolHelper <LeaveResponse> .GetProtocol(leaveResponse);

                    peer.Connections.First().Value?.SendData(cmd);
                }
            }
        }
 protected void OnClientConnectedInvoke(ServerConnectionBase e)
 {
     OnConnected?.Invoke(this, new ServerGenericEventArgs <ServerConnectionBase> {
         ServerConnectionBase = e
     });
 }
示例#7
0
 public TestPeer(ServerConnectionBase serverConnectionBase) : base(AppId)
 {
     AddConnection(serverConnectionBase);
 }
 public void RaiseClientConnected(ServerConnectionBase serverConnectionBase)
 {
     ClientConnected(serverConnectionBase);
 }
示例#9
0
 protected void ClientDisconnected(ServerConnectionBase e)
 {
     OnClientDisconnected?.Invoke(this, e);
 }