Ejemplo n.º 1
0
 void DisableServer(INetworkServer server)
 {
     server.PlayerAdded         -= OnServerAddPlayer;
     server.PlayerUpdated       -= OnServerUpdatePlayer;
     server.PlayerRemoved       -= OnServerRemovePlayer;
     GameSetupMenu.OnStartMatch -= OnServerStartMatch;
 }
Ejemplo n.º 2
0
        public SystemVariablesUpdater(IWorld world,
                                      ITribeManager tribeManager,
                                      IDbManager dbManager,
                                      IScheduler scheduler,
                                      IStrongholdManager strongholdManager,
                                      IForestManager forestManager,
                                      ISystemVariableManager systemVariableManager,
                                      INetworkServer networkServer,
                                      IChannel channel,
                                      BlockingBufferManager bufferManager,
                                      SocketAwaitablePool socketAwaitablePool)
        {
            this.world                 = world;
            this.tribeManager          = tribeManager;
            this.dbManager             = dbManager;
            this.scheduler             = scheduler;
            this.strongholdManager     = strongholdManager;
            this.forestManager         = forestManager;
            this.systemVariableManager = systemVariableManager;
            this.networkServer         = networkServer;
            this.channel               = channel;
            this.bufferManager         = bufferManager;
            this.socketAwaitablePool   = socketAwaitablePool;

            if (!string.IsNullOrEmpty(Config.api_id))
            {
                graphiteKeyPrefix = string.Format("servers.{0}_tribalhero_com.tribalhero.", Config.api_id);
            }
        }
Ejemplo n.º 3
0
 internal static IAsyncDisposable Start(
     INetworkServer networkServer,
     WebSocket webSocket)
 {
     return(new StreamForwarder(networkServer, webSocket)
            .Start());
 }
Ejemplo n.º 4
0
        /// <summary>
        /// Starts the matchmaking server on the specified port.
        /// </summary>
        /// <param name="port">The port to bind to.</param>
        /// <exception cref="System.ArgumentException">Application identifier parameter can't be null or empty.</exception>
        /// <exception cref="InvalidOperationException">
        /// <see cref="ApplicationIdentifier"/> must have a valid value before initialize.
        /// or
        /// You can't call multiple times to Start method.
        /// </exception>
        public void Start(int port)
        {
            if (string.IsNullOrEmpty(this.ApplicationIdentifier))
            {
                throw new InvalidOperationException($"{nameof(this.ApplicationIdentifier)} must have a valid value before initialize.");
            }

            if (this.networkServer != null)
            {
                throw new InvalidOperationException("You can't call multiple times to InitializeServer method.");
            }

            try
            {
                var fullIdentifier = $"{this.ApplicationIdentifier}.{this.ClientApplicationVersion}";

                this.networkServer = this.networkFactory.CreateNetworkServer(
                    fullIdentifier,
                    port,
                    (float)this.pingInterval.TotalSeconds,
                    (float)this.connectionTimeout.TotalSeconds);

                this.networkServer.Start();
                this.networkServer.ClientConnecting   += this.NetworkServer_ClientConnectionRequested;
                this.networkServer.ClientConnected    += this.NetworkServer_ClientConnected;
                this.networkServer.ClientDisconnected += this.NetworkServer_ClientDisconnected;
                this.networkServer.MessageReceived    += this.NetworkServer_MessageReceived;
            }
            catch
            {
                this.networkServer = null;
                throw;
            }
        }
Ejemplo n.º 5
0
 public void OnServerStopped(INetworkServer server)
 {
     serveStatus_start.Visibility     = BarItemVisibility.Never;
     serveStatus_stop.Visibility      = BarItemVisibility.Always;
     ribbonbtn_serveAct_start.Enabled = true;
     ribbonbtn_serveAct_stop.Enabled  = false;
 }
        /// <summary>
        /// Called whenever a network command is received that the task should deal with
        /// </summary>
        /// <param name="c">The command that was received</param>
        /// <param name="server">The server that received the command</param>
        /// <param name="handler">The client that sent the command. Use the client and server object if you need to send a reply</param>
        public override void ProcessNetworkCommand(ICommand c, INetworkServer server, Socket client)
        {
            eCommands command = (eCommands)c.CommandType;

            switch (command)
            {
            case eCommands.Message:
                string msg = c.getParameterAsString((int)eMessageCommandParameters.Message);
                logger.Info("Received message from:" + client.RemoteEndPoint.ToString() + ", " + msg);
                break;

            case eCommands.TaskCompleted:
            {
                logger.Info("Received task completed command from:" + client.RemoteEndPoint.ToString());

                _sendCommandStopTrial();
                _sendCommandFadeOut();
            }
            break;

//                default:
//                    logger.Info("Received unknown command " + c.ToString() + " from:" + client.RemoteEndPoint.ToString() + "\r\n" + c.ToString());
//                    break;
            }
        }
Ejemplo n.º 7
0
 internal Server(INetworkServer server, MatchConfig config) : base(server, config)
 {
     // TODO(james7132): Run server simulation for momentary state syncs
     NetworkServer.ReceivedInputs += OnRecievedInputs;
     CurrentInput = new MatchInput(config);
     NextInput    = new MatchInput(config);
     InputBuffer  = new MatchInput[1];
 }
Ejemplo n.º 8
0
 public ServerActor(INetworkModel networkModel, string address) : base(networkModel)
 {
     Address = address;
     Server  = networkModel.CreateServer(address, false);
     Server.MessageReceived    += Server_MessageReceived;
     Server.ClientConnected    += Server_ClientConnected;
     Server.ClientDisconnected += Server_ClientDisconnected;
 }
Ejemplo n.º 9
0
 public StreamForwarder(
     INetworkServer networkServer,
     WebSocket remoteSocket)
 {
     _networkServer = networkServer;
     _remoteSocket  = new WebSocketStreamer(
         remoteSocket, _cancellationTokenSource);
 }
    public void Dispose()
    {
        MessageReceived = null;;
        MessageSent     = null;;

        _server.Dispose();
        _server = null;
    }
Ejemplo n.º 11
0
 internal static IAsyncDisposable Start(
     INetworkServer networkServer,
     SpdySession spdySession,
     PortForward portForward)
 {
     return(new SpdyStreamForwarder(networkServer, spdySession, portForward)
            .Start());
 }
Ejemplo n.º 12
0
        public void OnServerStarted(INetworkServer server, StartStatus status)
        {
            //TCP服务器启动
            serveStatus_start.Visibility = BarItemVisibility.Always;
            serveStatus_stop.Visibility  = BarItemVisibility.Never;

            ribbonbtn_serveAct_start.Enabled = false;
            ribbonbtn_serveAct_stop.Enabled  = true;
        }
Ejemplo n.º 13
0
 public ButterflyServer(
     INetworkServer networkServer,
     IConnectedClients connectedClients,
     ConnectedClientInfoHandler connectedClientInfoHandler)
 {
     this.networkServer              = networkServer;
     this.connectedClients           = connectedClients;
     this.connectedClientInfoHandler = connectedClientInfoHandler;
 }
Ejemplo n.º 14
0
 public MapEditService(
     ILogger logger,
     IHostApplicationLifetime hostApplicationLifetime,
     INetworkServer networkServer)
 {
     _hostApplicationLifetime = hostApplicationLifetime;
     _networkServer           = networkServer;
     _logger = logger.ForContext <MapEditService>();
 }
Ejemplo n.º 15
0
 public void OnServerStarted(INetworkServer server, StartStatus status)
 {
     if (status == StartStatus.FAIL_ALREADY_STARTED || status == StartStatus.SUCCESS)
     {
     }
     else
         MessageBox.Show("Unknown Error occurred");
     
 }
Ejemplo n.º 16
0
 private SpdyStreamForwarder(
     INetworkServer networkServer,
     SpdySession spdySession,
     PortForward portForward)
 {
     _networkServer = networkServer;
     _spdySession   = spdySession;
     _portForward   = portForward;
 }
Ejemplo n.º 17
0
        public BaseNetworkClient(EEClient client, INetworkServer server)
        {
            Id      = Guid.NewGuid();
            Server  = server;
            _client = client;
            _client.DataReceived += Handle;
            _client.Disconnected += OnDisconnect;

            OnConnected();
        }
Ejemplo n.º 18
0
 public void OnServerStarted(INetworkServer server, StartStatus status)
 {
     if (status == StartStatus.FAIL_ALREADY_STARTED || status == StartStatus.SUCCESS)
     {
     }
     else
     {
         MessageBox.Show("Unknown Error occurred");
     }
 }
Ejemplo n.º 19
0
 internal Server(INetworkServer server, MatchConfig config) : base(server, config)
 {
     NetworkServer.ReceivedInputs += OnRecievedInputs;
     NetworkServer.PlayerRemoved  += OnRemovePlayer;
     InputContext    = new MatchInputContext(config);
     InputHistory    = new InputHistory <MatchInput>(new MatchInput(config));
     NetworkConfig   = Config.Get <NetworkConfig>();
     ClientTimesteps = new Dictionary <int, uint>();
     StateSendTimer  = 0;
 }
Ejemplo n.º 20
0
        void server_OnCrash(INetworkServer server)
        {
            Console.WriteLine("Server Crash: {0} on Port {1}", server, server.Port);

            server.Stop();
            if (server is BaseServer)
            {
                Servers.Remove((BaseServer)server);
            }
        }
Ejemplo n.º 21
0
 /// <summary>
 /// Stops the local NetworkServer.
 /// </summary>
 /// <remarks>
 /// This will forcibly disconnect all connected clients.
 /// </remarks>
 public void StopServer()
 {
     if (!IsServer)
     {
         return;
     }
     Server.Dispose();
     Server = null;
     Debug.Log("Server Stopped.");
 }
Ejemplo n.º 22
0
        /// <summary>
        /// 网络集成测试
        /// </summary>
        public void NetworkIntergrateTest <T, V>(string connectStr)
            where T : INetworkServer, new()
            where V : INetworkClient, new()
        {
            //开启服务器
            INetworkServer server = NetworkFactory.CreateNetworkServer <T>();

            server.StartListen(connectStr);

            //测试用客户端进行连接
            INetworkClient client = null;

            ThreadPool.QueueUserWorkItem((o) => {
                Thread.Sleep(50); //假设50毫秒服务器可以开起来
                client = NetworkFactory.CreateNetworkClient <V>();
                client.Connect(connectStr);
            });

            //服务器获得新的session
            INetworkClientSession session = BlockWaitNewClient(server);

            Assert.IsNotNull(session);
            Assert.IsNotNull(client);
            Assert.IsTrue(client.Connected);

            //测试客户端往服务器发消息
            var testMsg = new GameMessage()
            {
                stateCode = 9999
            };

            client.Send(testMsg);
            var msg = BlockRead(session);

            Assert.AreEqual(msg.stateCode, 9999);

            //测试服务器往客户端发消息
            session.Send(new SyncMessage()
            {
                stateCode = 9993, timeleft = 3333
            });
            msg = BlockRead(client);
            Assert.IsTrue(msg is SyncMessage);
            Assert.AreEqual(msg.stateCode, 9993);
            Assert.AreEqual((msg as SyncMessage).timeleft, 3333);

            //关闭连接
            client.Close();
            Assert.IsFalse(client.Connected);
            session.Close();
            Assert.IsFalse(session.Connected);

            //关闭服务器
            server.Shutdown();
        }
    public async Task <bool> Connect(FakeSocketProvider fakeSocketProvider)
    {
        if (_server == null)
        {
            _server = new NetworkServer();
        }
        _server.RegisterListener(this);
        ((NetworkServer)_server).StartListening(fakeSocketProvider);

        return(true);
    }
Ejemplo n.º 24
0
        public GameServer(IKernel kernel)
        {
            Debug.WriteLine("GameServer::.ctor");
            _kernel = kernel;

            _clientsManager = _kernel.Get<IClientsManager>();
            _networkServer = _kernel.Get<INetworkServer>();

            _worldManager = new WorldManager();
            Controllers.ControllersRegistration.Register();
        }
Ejemplo n.º 25
0
 public MapEditService(
     ILogger logger,
     IHostApplicationLifetime hostApplicationLifetime,
     INetworkServer networkServer,
     IOptions <ServerSettings> serverSettings)
 {
     _hostApplicationLifetime = hostApplicationLifetime;
     _networkServer           = networkServer;
     _serverSettings          = serverSettings.Value;
     _logger = logger.ForContext <MapEditService>();
 }
Ejemplo n.º 26
0
 internal Server(INetworkServer server, MatchConfig config) : base(server, config)
 {
     NetworkServer.ReceivedInputs += OnRecievedInputs;
     InputContext    = new MatchInputContext(config);
     LatestInput     = new MatchInput[1];
     LatestInput[0]  = new MatchInput(config);
     InputHistory    = new InputHistory <MatchInput>(LatestInput[0]);
     NetworkConfig   = Config.Get <NetworkConfig>();
     ClientTimesteps = new Dictionary <uint, uint>();
     StateSendTimer  = 0;
 }
        /// <summary>
        /// Called from the main control loop whenever a network command is received
        /// </summary>
        public override void ProcessNetworkCommand(ICommand c, INetworkServer server, Socket handler)
        {
            // USER command == data from UE4
            if (c.CommandType == 1000)
            {
                // parameter 0 == position
                unrealPosition     = c.getParameterAsVector3(0);
                unrealVelocity     = c.getParameterAsVector3(1);
                unrealAcceleration = c.getParameterAsVector3(2);
                unrealForce        = c.getParameterAsVector3(3);

                ((UnrealLandscapesDemoPanel)panel).setUnrealData(unrealPosition, unrealVelocity, unrealAcceleration, unrealForce);
            }
        }
Ejemplo n.º 28
0
 public FrmSampleServer()
 {
     InitializeComponent();
     lights         = running_lights = cooling_fan = brights = false;
     blower         = wipers = 0;
     m_server       = new IocpTcpServer();
     svrcmd         = new ServerCmds();
     cfg_params     = new ConfigParams();
     cfg_params.set = false;
     params_form    = new ParamsForm(cfg_params);
     btnConnect_Click(new object(), new EventArgs());
     timer1.Enabled     = true;
     connection_timeout = 0;
 }
Ejemplo n.º 29
0
        /// <summary>
        /// 阻塞等待新客户端连入
        /// </summary>
        /// <param name="server"></param>
        /// <returns></returns>
        INetworkClientSession BlockWaitNewClient(INetworkServer server)
        {
            Semaphore sema1 = new Semaphore(0, 1);

            _blockWaitClientSession = null;

            server.OnNewClient += (session) =>
            {
                _blockWaitClientSession = session;
                sema1.Release();
            };
            sema1.WaitOne();
            return(_blockWaitClientSession);
        }
Ejemplo n.º 30
0
        // Server Methods

        void EnableServer(INetworkServer server)
        {
            server.PlayerAdded   += OnServerAddPlayer;
            server.PlayerUpdated += OnServerUpdatePlayer;
            server.PlayerRemoved += OnServerRemovePlayer;

            GameSetupMenu.OnStartMatch += OnServerStartMatch;

            foreach (var client in server.Clients)
            {
                InitalizePlayer(client);
            }
            OnServerUpdatedConfig();
        }
Ejemplo n.º 31
0
 public void StartServer(NetworkPortInfo networkPortInfo)
 {
     try
     {
         INetworkServerFactory serverFactory = new VNetworkServerFactory();
         _server = serverFactory.CreateTcpNetworkServer(SharedConfig.IsLittleEndian, "HallRoom");
         _server.ChannelConnected += ServerOnChannelConnected;
         _server.Listen(networkPortInfo, 1, SharedConfig.MutilThread);
     }
     catch (Exception e)
     {
         _logger.ErrorFormat("HallRoom Server start failed {0}", e);
     }
 }
Ejemplo n.º 32
0
        /// <summary>
        /// Shutdowns the matchmaking server on the specified port.
        /// </summary>
        public void Shutdown()
        {
            if (this.networkServer != null)
            {
                this.networkServer.Shutdown();
                this.networkServer.ClientConnecting   -= this.NetworkServer_ClientConnectionRequested;
                this.networkServer.ClientConnected    -= this.NetworkServer_ClientConnected;
                this.networkServer.ClientDisconnected -= this.NetworkServer_ClientDisconnected;
                this.networkServer.MessageReceived    -= this.NetworkServer_MessageReceived;
                this.networkServer = null;

                this.connectedPlayers.Clear();
                this.lobbyRooms.Clear();
            }
        }
Ejemplo n.º 33
0
        void server_OnCrash(INetworkServer server)
        {
            Console.WriteLine("Server Crash: {0} on Port {1}", server, server.Port);

            server.Stop();
            if (server is BaseServer)
                Servers.Remove((BaseServer)server);
        }
Ejemplo n.º 34
0
 public void OnServerStopped(INetworkServer server)
 {
 }
Ejemplo n.º 35
0
 public void OnServerAccepted(INetworkServer server, INetworkSocket socket)
 {
 }
Ejemplo n.º 36
0
 public bool OnAccept(INetworkServer server, IPInfo ipInfo)
 {
     return true;
 }
Ejemplo n.º 37
0
        /// <summary>
        /// Initializes the host.
        /// </summary>
        /// <param name="applicationIdentifier">The application identifier.</param>
        /// <param name="port">The port.</param>
        /// <exception cref="System.ArgumentException">Application identifier parameter can't be null or empty.</exception>
        /// <exception cref="System.InvalidOperationException">You can't call multiple times to InitializeHost method.</exception>
        public void InitializeHost(string applicationIdentifier, int port)
        {
            if (string.IsNullOrEmpty(applicationIdentifier))
            {
                throw new ArgumentException("Application identifier parameter can't be null or empty.");
            }

            if (this.networkServer != null)
            {
                throw new InvalidOperationException("You can't call multiple times to InitializeHost method.");
            }

            try
            {
                this.networkServer = this.factory.CreateNetworkServer(applicationIdentifier, port);
                this.networkServer.Start();
                this.networkServer.MessageReceived += (sender, message) => this.OnHostMessageReceived(message);
            }
            catch
            {
                this.networkServer = null;
                throw;
            }
        }
Ejemplo n.º 38
0
 /// <summary>
 /// Default constructor
 /// </summary>
 /// <param name="client">client</param>
 /// <param name="server">managing server</param>
 public IocpTcpSocket(TcpClient client, INetworkServer server):base()
 {
     m_client=client;
     m_server = server;
     NoDelay = server.NoDelay;
     IPEndPoint remoteIpEndPoint = m_client.Client.RemoteEndPoint as IPEndPoint;
     IPEndPoint localIpEndPoint = m_client.Client.LocalEndPoint as IPEndPoint;
     if (remoteIpEndPoint != null)
     {
         String socketHostName = remoteIpEndPoint.Address.ToString();
         m_ipInfo = new IPInfo(socketHostName, remoteIpEndPoint, IPEndPointType.REMOTE);
     }
     else if (localIpEndPoint != null)
     {
         String socketHostName = localIpEndPoint.Address.ToString();
         m_ipInfo = new IPInfo(socketHostName, localIpEndPoint, IPEndPointType.LOCAL);
     }
     
 }
Ejemplo n.º 39
0
 /// <summary>
 /// Server started callback
 /// </summary>
 /// <param name="server">server</param>
 /// <param name="status">start status</param>
 public void OnServerStarted(INetworkServer server, StartStatus status)
 {
     OnParallelServerStarted(this, status);
 }
Ejemplo n.º 40
0
 /// <summary>
 /// Server stopped callback
 /// </summary>
 /// <param name="server">server</param>
 public void OnServerStopped(INetworkServer server)
 {
     OnParallelServerStopped(this);
 }
 /// <summary>
 /// Server started callback
 /// </summary>
 /// <param name="server">server</param>
 /// <param name="status">start status</param>
 public void OnServerStarted(INetworkServer server, StartStatus status)
 {
     CallBackObj.OnServerStarted(this, status);
 }
 /// <summary>
 /// Server stopped callback
 /// </summary>
 /// <param name="server">server</param>
 public void OnServerStopped(INetworkServer server)
 {
     CallBackObj.OnServerStopped(this);
 }
 /// <summary>
 /// Accept callback
 /// </summary>
 /// <param name="server">server</param>
 /// <param name="ipInfo">connection info</param>
 /// <returns>the socket callback interface</returns>
 public INetworkSocketCallback OnAccept(INetworkServer server, IPInfo ipInfo)
 {
     return this;
 }