Esempio n. 1
0
        static void Init()
        {
            // Create new instance of configs. Parameter is "application Id". It has to be same on client and server.
            Config = new NetPeerConfiguration("game");

            // Set server port
            Config.Port = 14242;

            // Max client amount
            Config.MaximumConnections = 200;

            // Enable New messagetype. Explained later
            Config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);

            // Create new server based on the configs just defined
            Server = new NetServer(Config);

            // Start it
            Server.Start();

            // Eh..
            Console.WriteLine("Server Started");

            // Create list of "Characters" ( defined later in code ). This list holds the world state. Character positions
            clients = new List <Messenger>();

            // Check time
            DateTime time = DateTime.Now;

            // Create timespan of 30ms
            TimeSpan timetopass = new TimeSpan(0, 0, 0, 0, 30);

            // Write to con..
            Console.WriteLine("Waiting for new connections");
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            //run the server here
            server.Start();

            //Read console here
            while (true)
            {
                //Just some basic debugging and testing stuff
                string input = Console.ReadLine();
                if (input == "stop")
                {
                    server.Stop();
                    Environment.Exit(0);
                }
                else if (input == "send")
                {
                    SendFiles();
                }
                else
                {
                    InternalData d = new InternalData("rawtext", "", Encoding.ASCII.GetBytes(input));
                    server.SendBroadcast(d);
                }
            }

            //End of Main
        }
Esempio n. 3
0
        static void Main(string[] args)
        {
            NetPeerConfiguration config = new NetPeerConfiguration("garbagethrower");

            config.MaximumConnections = 1;
            config.Port              = 14242;
            config.PingInterval      = 2.0f;
            config.ConnectionTimeout = 2.0f;
            var server = new NetServer(config);

            server.Start();

            while (true)
            {
                NetIncomingMessage msg;
                while ((msg = server.ReadMessage()) != null)
                {
                    switch (msg.MessageType)
                    {
                    case NetIncomingMessageType.StatusChanged:
                        var status = (NetConnectionStatus)msg.ReadByte();
                        var reason = msg.ReadString();
                        Console.WriteLine("New status: " + status + " (" + reason + ")");
                        break;

                    case NetIncomingMessageType.WarningMessage:
                    case NetIncomingMessageType.VerboseDebugMessage:
                    case NetIncomingMessageType.ErrorMessage:
                    case NetIncomingMessageType.DebugMessage:

                        var str = msg.ReadString();
                        if (str.StartsWith("Malformed packet; stated") ||
                            str.StartsWith("Received unhandled library message") ||
                            str.StartsWith("Unexpected NetMessageType"))
                        {
                            break;                                     // we'll get a bunch of these and we're fine with that
                        }
                        Console.WriteLine(msg.MessageType + ": " + str);
                        break;

                    case NetIncomingMessageType.Data:
                        Console.WriteLine("Received " + msg.LengthBits + " bits of data");
                        break;

                    case NetIncomingMessageType.UnconnectedData:
                        Console.WriteLine("Received " + msg.LengthBits + " bits of unconnected data");
                        break;

                    default:
                        Console.WriteLine("Received " + msg.MessageType);
                        break;
                    }
                }
            }
        }
Esempio n. 4
0
        public void Start()
        {
            StartServerParameter sp = new StartServerParameter();

            sp.protocolVersion = new Nettention.Proud.Guid(Common.Vars.g_ProtocolVersion);
            sp.tcpPorts        = new IntArray();
            sp.tcpPorts.Add(Common.Vars.g_serverPort);
            sp.serverAddrAtClient = "175.204.115.46";
            sp.localNicAddr       = "175.204.115.46";
            sp.SetExternalNetWorkerThreadPool(netWorkerThreadPool);
            sp.SetExternalUserWorkerThreadPool(userWorkerThreadPool);

            m_netServer.Start(sp);
        }
Esempio n. 5
0
        public Game()
        {
            Console.WriteLine("Game");

            connections = new Dictionary <int, Player>();
            rooms       = new Dictionary <int, List <NetConnection> >();

            peerConfiguration = new NetPeerConfiguration(appIdentifier)
            {
                MaximumConnections = 128,
                Port = port
            };

            server = new NetServer(peerConfiguration);
            server.Start();
        }
Esempio n. 6
0
        public void StartServer()
        {
            NetPeerConfiguration config = new NetPeerConfiguration("chat");

            config.Port = 14242;
            server      = new NetServer(config);
            server.Start();

            if (server.Status == NetPeerStatus.Running)
            {
                Console.WriteLine("Server is running on port " + config.Port);
            }
            else
            {
                Console.WriteLine("Server not started...");
            }
            clients = new List <NetPeer>();
        }
Esempio n. 7
0
        public void Start()
        {
            NetPeerConfiguration config = new NetPeerConfiguration("MulTUNG");

            config.Port         = (int)Configuration.Get <long>("ServerPort", 5678);
            config.LocalAddress = IPAddress.Parse(Configuration.Get("LocalServerIP", "127.0.0.1"));
            config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);

            Server = new NetServer(config);
            Server.Start();

            Network.IsServer = true;

            ThreadPool.QueueUserWorkItem(_ =>
            {
                NetIncomingMessage msg;
                while (Server != null)
                {
                    msg = Server.WaitMessage(int.MaxValue);

                    if (msg == null)
                    {
                        continue;
                    }

                    HandleMessage(msg);

                    Server.Recycle(msg);
                }
            });

            World.AddNetObjects();
            World.LoadCircuitState();

            Network.StartPositionUpdateThread(Constants.PositionUpdateInterval);

            Log.WriteLine("Listening on port " + config.Port);
        }
        void Init(uint16_t inPort, byte worldCount, float ConnectionTimeout)
        {
            base.Init(worldCount);
            mNewNetworkId = new ushort[worldCount];
            mNewPlayerId  = new int[worldCount];
            for (byte i = 0; i < worldCount; ++i)
            {
                ResetNewNetworkId(i);
                mNewPlayerId[i] = 1;
            }

            NetPeerConfiguration config = new NetPeerConfiguration("game");

            config.MaximumConnections = 1000;
            config.Port = inPort;
            config.ConnectionTimeout = ConnectionTimeout;
            mNetPeer = new NetServer(config);
            mNetPeer.Start();

            algo = new NetXorEncryption(GetServer(), "AceTopSecret");

            // tcp
            SetListener(inPort);
        }
        static void Main(string[] args)
        {
            var config = new NetPeerConfiguration("application name")
            {
                Port = 12345
            };
            var server = new NetServer(config);

            server.Start();

            // server

            NetIncomingMessage msg;

            GameRoom newGameRoom = new GameRoom(null, "TEST", 8);

            NetworkSessionContainer.NetworkSessions.GameRooms.Add(newGameRoom);


            while (true)
            {
                //Ustawić odświerzanie co 16.666ms
                foreach (GameRoom gameRoom in NetworkSessionContainer.NetworkSessions.GameRooms)
                {
                    gameRoom.Update();
                }

                if ((msg = server.ReadMessage()) == null)
                {
                    continue;
                }


                switch (msg.MessageType)
                {
                case NetIncomingMessageType.ConnectionApproval:
                {
                    Console.WriteLine("Connected");
                    break;
                }

                case NetIncomingMessageType.VerboseDebugMessage:
                case NetIncomingMessageType.DebugMessage:
                case NetIncomingMessageType.WarningMessage:
                case NetIncomingMessageType.StatusChanged:
                {
                    NetConnectionStatus status = (NetConnectionStatus)msg.ReadByte();
                    break;
                }

                case NetIncomingMessageType.Data:
                {
                    short opcode = msg.ReadInt16();
                    if (opcode == 2000)      //Logowanie użytkownika
                    {
                        unsafe
                        {
                            if (!NetworkSessionContainer.NetworkSessions.UserSessions.Exists(x => x.Connection == msg.SenderConnection))
                            {
                                UserSession    session = new UserSession();
                                TypedReference tr      = __makeref(session);
                                IntPtr         ptr     = **(IntPtr **)(&tr);
                                Console.WriteLine(ptr);
                                session.Connection = msg.SenderConnection;
                                Random randID = new Random();
                                session.ID = randID.Next(1000000);         //martwić sie tym będe później
                                //session.ID = ptr.ToInt32();
                                session.Name = msg.ReadString();

                                NetOutgoingMessage outMessage = session.Connection.Peer.CreateMessage();
                                outMessage.Write((short)2000);
                                outMessage.Write(session.ID);
                                session.Connection.SendMessage(outMessage, NetDeliveryMethod.UnreliableSequenced,
                                                               outMessage.LengthBytes);
                                session.UserGameState = new MenuState();
                                NetworkSessionContainer.NetworkSessions.UserSessions.Add(session);
                                // Musze dorobić jakąś obsługe menu
                            }
                            else
                            {
                                //Zaimplementować że jest już taki gość
                            }

                            //TO NIE SPAWN A LOGIN

                            /*foreach (UserSession otherPlayers in UsersSessions.Sessions)
                             * {
                             *  NetOutgoingMessage informAboutPlayer = session.Connection.Peer.CreateMessage();
                             *  informAboutPlayer.Write((short)2620);
                             *  informAboutPlayer.Write(otherPlayers.ID, 32);
                             *  informAboutPlayer.Write("konserwa");
                             *  session.Connection.SendMessage(informAboutPlayer, NetDeliveryMethod.UnreliableSequenced, informAboutPlayer.LengthBytes);
                             *  Console.WriteLine($"Wysyłam pakiet od {session.ID} wysyłam dane o {otherPlayers.ID}");
                             *  //Console.WriteLine(BitConverter.ToString(informAboutPlayer.Data));
                             *
                             *
                             *  NetOutgoingMessage SendToCurrentPlayerAboutPlayers = otherPlayers.Connection.Peer.CreateMessage();
                             *  SendToCurrentPlayerAboutPlayers.Write((short)2620);
                             *  SendToCurrentPlayerAboutPlayers.Write(session.ID, 32);
                             *  SendToCurrentPlayerAboutPlayers.Write("konserwa");
                             *  otherPlayers.Connection.SendMessage(SendToCurrentPlayerAboutPlayers, NetDeliveryMethod.UnreliableSequenced, SendToCurrentPlayerAboutPlayers.LengthBytes);
                             *  Console.WriteLine($"Wysyłam pakiet od {otherPlayers.ID} wysyłam dane o {session.ID}");
                             * //  Console.WriteLine(BitConverter.ToString(SendToCurrentPlayerAboutPlayers.Data));
                             * }*/
                        }
                    }
                    else
                    {
                        //     NetworkSessionContainer.NetworkSessions.UserSessions.Find(x => x.Connection == msg.SenderConnection).UserGameState.Recive(msg);
                        foreach (UserSession user in NetworkSessionContainer.NetworkSessions.UserSessions)
                        {
                            if (user.Connection == msg.SenderConnection)
                            {
                                user.UserGameState.Recive(msg);
                            }
                        }
                    }



                    break;
                }

                case NetIncomingMessageType.ErrorMessage:
                    Console.WriteLine(msg.ReadString());
                    break;

                default:
                {
                    Console.WriteLine("Unhandled type: " + msg.MessageType);
                    break;
                }
                }

                //server.Recycle(msg);
            }
        }
Esempio n. 10
0
 public void Start()
 {
     _server.Start();
     StartGameLoop();
 }