Inheritance: Network.Base
        private Client client; // Socket

        void Start()
        {
            this.client = GameObject.Find("Manager").GetComponent<ClientManager>().Client;
            user = User.Instance;
            if (user.is_connected)
            {
                PhotonNetwork.playerName = user.username;

                PhotonPeer.RegisterType(typeof(Team), (byte)'T', ObjectToByteArray, ByteToTeam);
                PhotonPeer.RegisterType(typeof(Composition), (byte)'C', ObjectToByteArray, ByteToComposition);
                PhotonPeer.RegisterType(typeof(Player), (byte)'P', ObjectToByteArray, ByteToPlayer);
                PhotonPeer.RegisterType(typeof(User), (byte)'U', ObjectToByteArray, ByteToUser);
                PhotonPeer.RegisterType(typeof(List<string>), (byte)'L', ObjectToByteArray, ByteToLS);

                PhotonHastable props = new PhotonHastable();

                props.Add("Team", Settings.Instance.Selected_Team);
                props.Add("User", user);

                PhotonNetwork.player.SetCustomProperties(props);

                PhotonNetwork.ConnectUsingSettings(game_version_);
                this.room_name = user.username + "-" + rand.Next(1000);
            }
        }
Beispiel #2
0
 static void Main(string[] args)
 {
     EventManager ev = new EventManager();
     ev.Register("Network.Game.GameStart", o => Console.WriteLine("le jeu débute"));
     Parser p = new Parser();
     Client c = new Client("163.5.218.4", 4242, ev, p.Parse);
     new JoinLobby().Pack(c.Writer, Console.ReadLine(), "Zeus");
     Console.ReadLine();
 }
Beispiel #3
0
        public void SetupEachTest()
        {
            clients = new List<TestClient>();

            server = new Server();
            server.StartListening(LocalHost, TestPort); // Start listening on port.

            singleClient = new Client();
        }
Beispiel #4
0
 public ServerSelector(SpriteBatch spriteBatch, GraphicsDeviceManager graphics, string persoName, string playerName)
 {
     _spriteBatch = spriteBatch;
     PersoName = persoName;
     PlayerName = playerName;
     Client = new Client("metastruggle.eu", 5555, GameEngine.EventManager, new Parser().Parse);
     GameEngine.EventManager.Register("Network.Master.ServerList", ReceiveServers);
     GameEngine.EventManager.Register("Network.Game.GameStart", GameBegin);
     AskList();
 }
Beispiel #5
0
 public void Parse(Client client, Packet.Packet packet, IEventDispatcher eventDispatcher)
 {
     if (!_packets.ContainsKey(packet.Header.ID))
     {
         if (PacketNotFound != null)
             PacketNotFound.BeginInvoke(packet, null, null);
     }
     else
         _packets[packet.Header.ID].UnPack(client, packet, eventDispatcher);
 }
Beispiel #6
0
        void NextButton()
        {
            System.Threading.Thread.Sleep(200);

            var listServer = Menu.Items["ListServer.Item"] as ClassicList;
            if ((listServer == null || listServer.Selected == null))
                return;
            Menu.Items["WaitingRoom.Item"].IsDrawable = true;
            Menu.Items["NextButton.Item"].IsDrawable = false;

            var serverItem = listServer.Selected[1].Split(':');

            Client = new Client(serverItem[0], int.Parse(serverItem[1]), GameEngine.EventManager, new Parser().Parse);
            new JoinLobby().Pack(Client.Writer, PlayerName, PersoName);
        }
        public NetworkEnvironment(SpriteBatch spriteBatch, GameStartDatas gs, Client client, string currentchar)
        {
            RegisterEvents();
            CurrentCharacterName = currentchar;

            SceneManager = SceneManager.CreateScene(
                new Vector3(-5, 5, -30), //Position initiale de la caméra
                new Vector3(0, 0, 0), //Point visé par la caméra
                spriteBatch); //SpriteBatch

            Client = client;

            GameStart(gs);

            SceneManager.Camera.FollowsCharacters(SceneManager.Camera, SceneManager.Items.FindAll(e => e is Character));
        }
Beispiel #8
0
        static void Ping()
        {
            while (true)
            {
                Console.WriteLine("=== ping des serveurs ===");

                foreach (var masterServerDatase in Servers.GetRange(0, Servers.Count))
                {
                    var c = new Client(masterServerDatase.IP, masterServerDatase.Port, new EventManager(),
                                       new Parser().Parse);
                    if (!c.Connected)
                        RemoveServer(masterServerDatase);
                    else
                        c.Disconnect();
                }

                Thread.Sleep(5000);
            }
        }
Beispiel #9
0
        void ListeningThread()
        {
            while (IsRunning)
            {
                try
                {
                    var c = new Client(_listener.AcceptTcpClient(), _eventDispatcher, _parserMethod,
                                       cc =>
                                       {
                                           cc.BaseClient.NoDelay = true;
                                           if (ClientConnected != null)
                                               ClientConnected.BeginInvoke(cc, null, null);
                                       });

                    c.OnDisconnect += OnClientDisconnected;
                    ConnectedClients.Add(c);
                }
                catch {}
            }
        }
Beispiel #10
0
        void OnClientDisconnected(Client c)
        {
            ConnectedClients.Remove(c);

            if (ClientDisconnected != null)
                ClientDisconnected.BeginInvoke(c, null, null);
        }
Beispiel #11
0
        void ReceiveServers(object data)
        {
            Client = new Client("metastruggle.eu", 5555, GameEngine.EventManager, new Parser().Parse);

            var listServers = (List<MasterServerDatas>)data;
            var servers = new List<string[]>();
            foreach (var s in listServers)
                servers.Add(new[] { s.Map, s.IP + ":" + s.Port, s.ConnectedPlayer + "/" + s.MaxPlayer });

            Client.Disconnect();
            Menu.Add("ListServer.Item", new ClassicList(new Rectangle(10, 10, 80, 50), servers, new Dictionary<string, int>
                {
                    {"Map",18}, {"IP:Port",11}, {"Player", 3}
                }, RessourceProvider.Fonts["HUDlittle"], Color.White, Color.DarkOrange, "MSTheme"));
        }
        private void IdentifyDevice(Messenger msgr)
        {
            try
            {
                MessageType type;
                msgr.TcpClient.ReceiveTimeout = 30000;
                byte[] buffer = msgr.ReceiveMessage(out type);
                msgr.TcpClient.ReceiveTimeout = 0;

                if (type == MessageType.Command)
                {
                    string id = Encoding.ASCII.GetString(buffer);
                    Device d = null;

                    if (id.StartsWith("WC:"))
                    {
                        Webcam w = new Webcam(msgr, id, _view.BasePath + @"\" + id.Substring(4));
                        w.Disconnected += OnDisconnect;
                        w.MotionDetected += OnMotionDetect;
                        w.Recorded += (source) => _view.Status = "Webcam " + source.Name + " started recording";
                        w.MotionStopped += (source) =>
                            {
                                ((Webcam)source).StopRecording();
                                _view.Status = "Webcam " + source.Name + " stopped recording";
                            };
                        w.AddClient(this);
                        _view.AddedWebcam = w.Name;
                        _view.Status = "Webcam " + w.Name + " is now connected";
                        d = w;
                    }
                    else if (id.StartsWith("CL:"))
                    {
                        Client c = new Client(msgr, this, id);
                        c.Disconnected += OnDisconnect;
                        c.WebcamChanged += (source) => _view.Status = ((Client)source).EventArg;
                        _view.AddedClient = c.Name;
                        _view.Status = "Client " + c.Name + " is now connected";
                        d = c;
                    }

                    if (d == null)
                        msgr.Dispose();
                    else
                    {
                        _devices.AddOrUpdate(id, d, (key, value) =>
                            {
                                value.Dispose();
                                return d;
                            });
                        d.Listen();
                    }
                }
            }
            catch { msgr.Dispose(); }
        }
Beispiel #13
0
 public void SetEnvironnementDatas(byte id, bool playing, Client client)
 {
     Playing = playing;
     Client = client;
     ID = id;
 }