protected override void OnStart() { userName = GetType().Name; PacketStream stream; ConnectorInfo info; stream = _agent.Connect("127.0.0.1", Port.Database); stream.Write(new ConnectorInfo(GetType().Name)); _messenger.Register("Database", stream); Console.WriteLine("Database connected."); _agent.Bind("127.0.0.1", (Port)Enum.Parse(typeof(Port), GetType().Name), 1); stream = _agent.Listen(); info = (ConnectorInfo)stream.Read().body; _messenger.Register(info.name, stream); Console.WriteLine(info.name + " connected."); foreach (var key in _messenger.Keys) { StartCoroutine(Dispatcher(key)); } _messenger.Start(); }
protected override void OnStart() { _messenger = new Messenger(_handler); PacketStream stream; ConnectorInfo info; stream = _agent.Connect("127.0.0.1", Port.Database); stream.Write(new ConnectorInfo("Login")); _messenger.Register("Database", stream); Console.WriteLine("Database connected."); //Listen Proxy _agent.Bind("127.0.0.1", Port.Login, 1); stream = _agent.Listen(); info = (ConnectorInfo)stream.Read().body; _messenger.Register(info.name, stream); Console.WriteLine(info.name + " connected."); foreach (var key in _messenger.Keys) { var dispatcher = Task.Run(() => { while (stopped == false) { _messenger.Dispatch(key); } }); _dispatchers.Add(key, dispatcher); } _messenger.Start(); }
protected override void OnStart() { _messenger.Register("Proxy", _agent.Connect(serverIP, Port.Proxy)); Console.WriteLine("Proxy connected."); foreach (var key in _messenger.Keys) { StartCoroutine(Dispatcher(key)); } _messenger.Start(); }
protected override void Initialize() { spriteBatch = new SpriteBatch(GraphicsDevice); _netAgent = new NetworkAgent(AgentRole.Client, "Umbra"); EntitySystem.BlackBoard.SetEntry("Game", this); EntitySystem.BlackBoard.SetEntry("ContentManager", Content); EntitySystem.BlackBoard.SetEntry("SpriteBatch", spriteBatch); EntitySystem.BlackBoard.SetEntry("GraphicsDevice", GraphicsDevice); EntitySystem.BlackBoard.SetEntry("ContentManager", Content); EntitySystem.BlackBoard.SetEntry("NetworkAgent", _netAgent); _entityWorld = new EntityWorld(); // create camera Vector3 camPosition = new Vector3(0, 10, 5); Matrix camRotation = Matrix.CreateFromAxisAngle(new Vector3(1, 0, 0), MathHelper.ToRadians(-65.0f)); float aspectRatio = (float)GraphicsDevice.Viewport.Width / GraphicsDevice.Viewport.Height; CameraComponent cameraComponent = new CameraComponent(camPosition, camRotation, aspectRatio); Entity cameraEntity = _entityWorld.CreateEntity(); cameraEntity.AddComponent(cameraComponent); EntitySystem.BlackBoard.SetEntry("Camera", cameraComponent); //// TEMP //// Map map = new Map(100, 100); Entity mapEntity = _entityWorld.CreateEntity(); mapEntity.AddComponent(new TileMapComponent(map)); EntitySystem.BlackBoard.SetEntry("Map", map); //// TEMP //// _entityWorld.InitializeAll(new[] { GetType().Assembly }); CrawEntityManager.Instance.Initialize(_entityWorld, new ClientEntityFactory(_entityWorld)); _netAgent.Connect("127.0.0.1"); base.Initialize(); }
protected override void OnStart() { _messenger = new Messenger(this); _confirmMessenger = new Messenger(this); Action <Port> connector = (Port port) => { var stream = _agent.Connect("127.0.0.1", port); stream.Write(new ConnectorInfo("Proxy")); _messenger.Register(port.ToString(), stream); Console.WriteLine(port.ToString() + " connected."); _worldByUser.Add(port.ToString(), port.ToString()); _serverKeys.Add(port.ToString()); _rpcBufferByWorld.Add(port.ToString(), new List <RPC>()); }; connector(Port.Login); connector(Port.Town); connector(Port.Forest); connector(Port.Mine); connector(Port.Boss); foreach (var key in _messenger.Keys) { var dispatcher = Task.Run(() => { while (stopped == false) { _messenger.Dispatch(key); } }); _dispatchers.Add(key, dispatcher); } _accepter = Task.Run(() => { _agent.Bind("0.0.0.0", Port.Proxy, 4); while (stopped == false) { if (_agent.HasConnectReq()) { string stringID = _currentConfirmId.ToString(); int ID = _currentConfirmId; lock (_lock) { _confirmMessenger.Register(stringID, _agent.Listen()); _confirmMessenger.Send(stringID, new ConfirmID(ID)); } _currentConfirmId++; Console.WriteLine("Client connected."); } } }); _confirm = Task.Run(() => { while (stopped == false) { lock (_lock) { foreach (var confirmID in _confirmMessenger.Keys) { _confirmMessenger.Dispatch(confirmID); } } } }); _client = Task.Run(() => { while (stopped == false) { lock (_lock) { foreach (var key in _messenger.Keys) { if (_serverKeys.Contains(key) == false) { _messenger.Dispatch(key); } } } } }); _messenger.Start(); _confirmMessenger.Start(); }