Beispiel #1
0
        private void runThis()
        {
            Packet p;
            while (this.go)
            {
                p = nw.getNext();
                if (p == null)
                {
                    foreach (IPEndPoint ep in connections.Keys)
                    {
                        SYNCPacket ps = new SYNCPacket();
                        ps.Dest = ep;
                        this.nw.commitPacket(ps);
                    }
                    continue;
                }
                //Console.WriteLine(p.ptype);

                switch (p.ptype)
                {
                    case Packet.PacketType.HANDSHAKE:
                        if (!connections.ContainsKey(p.Dest))
                        {
                            Console.WriteLine("Server - New connection from: " + p.Dest);
                            connections[p.Dest] = new ConnectionID(p.Dest);
                            Console.WriteLine("Server - Added Connection: " + connections[p.Dest].ID);
                            HandshakePacket hs = new HandshakePacket();
                            hs.Dest = p.Dest;
                            nw.commitPacket(hs);
                        }
                        break;

                    case Packet.PacketType.STC:
                        //Console.WriteLine("Server - Receivd State Change from client... who do they think they are?");
                        Environment.Exit(1);
                        break;

                    case Packet.PacketType.SYNC:
                        if (connections.ContainsKey(p.Dest))
                        {
                            //Console.WriteLine("Server - SYNC Reply from: " + connections[p.Dest].ID);
                        }
                        else
                        {
                            Console.WriteLine("Server - ERROR Unregistered SYNC");
                        }
                        break;

                    case Packet.PacketType.PING:
                        if (connections.ContainsKey(p.Dest))
                        {
                            //Console.WriteLine("Server - Ping from connection: " + connections[p.Dest].ID);
                            PingPacket ps = new PingPacket();
                            ps.Dest = p.Dest;
                            nw.commitPacket(ps); //ACK the ping
                        }
                        else
                        {
                            Console.WriteLine("Server ERROR - Unregistered PING");
                        }
                        break;

                    case Packet.PacketType.CMD:
                        //Actually handle this
                        //Console.WriteLine("Server - Got CMD from: " + connections[p.Dest].ID);
                        Command cmd = new Command(p.data);
                        lock (commandQ)
                            this.commandQ.Add(cmd);
                        break;
                    case Packet.PacketType.MSC:
                        //Actually handle this
                        //Console.WriteLine("Server - Got MSC from: " + connections[p.Dest].ID);
                        MenuState msc = new MenuState(p.data);
                        if (connections.ContainsKey(p.Dest))
                        {
                            ConnectionID cid = connections[p.Dest];
                            Tuple<ConnectionID, MenuState> newMQ = new Tuple<ConnectionID, MenuState>(cid, msc);
                            lock (mscQ)
                                this.mscQ.Enqueue(newMQ);
                        }
                        break;
                }
                this.globalStats.rcvdPkts++;
            }
        }
Beispiel #2
0
 private void syncServer()
 {
     SYNCPacket ss = new SYNCPacket();
     ss.setDest(server);
     this.nw.commitPacket(ss);
 }