Esempio n. 1
0
        public void sendFullInfo(string ip)
        {
            NetworkCarrierFull c = new NetworkCarrierFull(this.game.players, this.game.desk);

            newConnection(ip, "FULL");
            try {
                this.formatter.Serialize(this.stream, c);
                return;
            } catch (Exception e) {
                Console.WriteLine(e.Message);
            }
        }
Esempio n. 2
0
 public void networkUpdate(NetworkCarrierFull c)
 {
     lock (this.gameLock) {
         this.newData = true;
         this.players = c.players;
         foreach (Scrabble.Player.Player p in this.players)
         {
             p.SetGame(this);
         }
         this.desk = c.playDesk;
         this.desk.setGame(this);
     }
 }
Esempio n. 3
0
        private void Recive()
        {
            this.client = listener.AcceptTcpClient();
            this.stream = this.client.GetStream();

            this.buffer = new byte[4];
            this.stream.Read(buffer, 0, buffer.Length);
            string mes = encoder.GetString(buffer);

            if (mes.StartsWith("FULL"))
            {
#if DEBUG
                Console.WriteLine("Přijimam FULL update");
#endif
                NetworkCarrierFull c = ( NetworkCarrierFull )formatter.Deserialize(this.stream);
                this.game.networkUpdate(c);
            }

            if (mes.StartsWith("MINI"))
            {
#if DEBUG
                Console.WriteLine("Přijimam MINI update");
#endif
                NetworkCarrierMini c = ( NetworkCarrierMini )formatter.Deserialize(this.stream);
                this.game.networkUpdate(c);
            }

            if (mes.StartsWith("MOVE"))
            {
                NetworkCarrierPlayer c = (NetworkCarrierPlayer)formatter.Deserialize(this.stream);
                lock (this.game.gameLock) {
                    this.game.yourTurn = true;
                    this.game.ncp      = c;
                }

                while (true)
                {
                    try {
                        Thread.Sleep(Timeout.Infinite);
                    } catch (ThreadInterruptedException) {}
                    lock (this.game.gameLock) {
                        if (this.game.turnDone)
                        {
                            this.game.turnDone = false;
                            this.game.yourTurn = false;
                            formatter.Serialize(this.stream, this.game.move);
                            this.stream.Flush();
                            this.stream.Close();
                            break;
                        }
                    }
                }
            }

            if (mes.StartsWith("EXIT"))
            {
                this.listener.Stop();
                try { this.stream.Close(); } catch {}
                try { this.client.Close(); } catch {}
                this.end = true;
            }
        }