Esempio n. 1
0
File: Coob.cs Progetto: Wroud/Coob
        public Coob(CoobOptions options)
        {
            this.Options = options;
            MessageQueue = new ConcurrentQueue<Packet.Base>();
            PacketParsers = new Dictionary<int, PacketParserDel>();
            Clients = new Dictionary<ulong, Client>();
            World = new World(options.WorldSeed);

            PacketParsers.Add((int)CSPacketIDs.EntityUpdate, Packet.EntityUpdate.Parse);
            PacketParsers.Add((int)CSPacketIDs.Interact, Packet.Interact.Parse);
            PacketParsers.Add((int)CSPacketIDs.Shoot, Packet.Shoot.Parse);
            PacketParsers.Add((int)CSPacketIDs.ClientChatMessage, Packet.ChatMessage.Parse);
            PacketParsers.Add((int)CSPacketIDs.ChunkDiscovered, Packet.UpdateChunk.Parse);
            PacketParsers.Add((int)CSPacketIDs.SectorDiscovered, Packet.UpdateSector.Parse);
            PacketParsers.Add((int)CSPacketIDs.ClientVersion, Packet.ClientVersion.Parse);

            try
            {
                clientListener = new TcpListener(IPAddress.Any, options.Port);
                clientListener.Start();
                clientListener.BeginAcceptTcpClient(onClientConnect, null);
            }
            catch (SocketException e)
            {
                if (e.ErrorCode == 10048)
                    Log.Error("Something is already running on port " + options.Port + ". Can't start server.");
                else
                    Log.Error("Unknown error occured while trying to start server:\n" + e);

                Log.Display();
                Environment.Exit(1);
            }
        }
Esempio n. 2
0
        public Coob(CoobOptions options)
        {
            Options = options;

            elapsedDt = new Stopwatch();

            MessageQueue  = new ConcurrentQueue <Packet.Base>();
            PacketParsers = new Dictionary <int, PacketParserDel>();
            Clients       = new Dictionary <ulong, Client>();
            World         = new World(options.WorldSeed, this);

            // TODO Refactor with new design later
            PacketParsers.Add((int)CSPacketIDs.EntityUpdate, Packet.EntityUpdate.Parse);
            PacketParsers.Add((int)CSPacketIDs.Interact, Packet.Interact.Parse);
            PacketParsers.Add((int)CSPacketIDs.Hit, Packet.Hit.Parse);
            // TODO: PacketParsers.Add((int)CSPacketIDs.Stealth, Packet.Stealth.Parse);
            PacketParsers.Add((int)CSPacketIDs.Shoot, Packet.Shoot.Parse);
            PacketParsers.Add((int)CSPacketIDs.ClientChatMessage, Packet.ChatMessage.Parse);
            PacketParsers.Add((int)CSPacketIDs.ChunkDiscovered, Packet.UpdateChunk.Parse);
            PacketParsers.Add((int)CSPacketIDs.SectorDiscovered, Packet.UpdateSector.Parse);
            PacketParsers.Add((int)CSPacketIDs.ClientVersion, Packet.ClientVersion.Parse);

            try
            {
                clientListener = new TcpListener(IPAddress.Any, options.Port);
                clientListener.Start();
                clientListener.BeginAcceptTcpClient(OnClientConnect, null);
            }
            catch (SocketException e)
            {
                if (e.ErrorCode == 10048)
                {
                    Log.Error("Something is already running on port " + options.Port + ". Can't start server.");
                }
                else
                {
                    Log.Error("Unknown error occured while trying to start server:\n" + e);
                }

                Log.Display();
                Environment.Exit(1);
            }

            Log.Info("Listening on port: " + options.Port);
        }