Beispiel #1
0
        public Boolean Open()
        {
            var result = true;

            if (nethandler == null || netaddress == null || netport == 0 || netmax == 0)
            {
                result = false;
            }
            else
            {
                if (netconn == null)
                {
                    netconfig      = new NetPeerConfiguration("AuthServer");
                    netconfig.Port = netport;
                    netconfig.MaximumConnections = netmax;
                    netconn = new Lidgren.Network.NetServer(netconfig);
                    netconn.RegisterReceivedCallback(new SendOrPostCallback(nethandler), new SynchronizationContext());
                }
                try {
                    netconn.Start();
                    result = true;
                } catch {
                    result = false;
                }
            }
            return(result);
        }
Beispiel #2
0
        public static void Initialize()
        {
            NetServer = new NetServer(new NetPeerConfiguration("XnaMultiplayerGame")
                                      	{
                                      		Port = 5555
                                      	});

            NetServer.RegisterReceivedCallback(MessageReceived);

            NetServer.Start();

            Clients = new List<Client>();
        }
Beispiel #3
0
        public static void start()
        {
            net = new NetServer(config);

            net.RegisterReceivedCallback(new SendOrPostCallback((e) =>
            {
                message = ((NetServer)e).ReadMessage();
                messageRecieved(message);
            }), new SynchronizationContext());

            print("info", "Starting...");
            net.Start();
            print("info", "Server running");
        }
        public void Init(string app_identifier, int listen_port, int max_connections, int interval_ms, bool use_multi_thread)
        {
            this.app_identifier = app_identifier;
            this.interval_ms = interval_ms;

            NetPeerConfiguration config = new NetPeerConfiguration(this.app_identifier);
            config.MaximumConnections = max_connections;
            config.Port = listen_port;

            net_server = new NetServer(config);

            if (SynchronizationContext.Current == null)
            {
                SynchronizationContext.SetSynchronizationContext(new STASynchronizationContext());
            }

            if (use_multi_thread == false && SynchronizationContext.Current != null)
            {
                net_server.RegisterReceivedCallback(new SendOrPostCallback(GotMessage));
            }
            else
            {
                net_worker = new BackgroundWorker();
                net_worker.DoWork += new DoWorkEventHandler(net_worker_DoWork);
                net_worker.RunWorkerCompleted += new RunWorkerCompletedEventHandler(net_worker_RunWorkerCompleted);
            }

            tick_timer = new Timer(e =>
            {
                try
                {
                    if (OnTick != null && use_multi_thread && SynchronizationContext.Current != null)
                    {
                        SynchronizationContext.Current.Post(x =>
                        {
                            OnTick();
                        }, null);

                    }
                    else
                    {
                        OnTick();
                    }
                }
                catch (System.Exception ex)
                {
                    Console.WriteLine("Tick timer exception = {0}", ex.Message);
                }
            });
        }
Beispiel #5
0
        private ServerManager()
        {
            WorldHelper.SetMessagingProviders(_ClientToServer, _ServerToClient);

             SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());

             NetPeerConfiguration peerConfig = ServerWorldManager.Instance.Configuration.Network.CreateNetPeerConfigurationUdp();
             peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.DebugMessage, true);
             peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.ErrorMessage, true);
             peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.VerboseDebugMessage, true);
             peerConfig.SetMessageTypeEnabled(NetIncomingMessageType.WarningMessage, true);

             _Server = new NetServer(peerConfig);
             _Server.RegisterReceivedCallback(new SendOrPostCallback(ReceivedMessage));

             _WebServer = new WebHost(ServerWorldManager.Instance.Configuration.Network.Web);
        }
Beispiel #6
0
 public Server()
 {
     // set up network
     NetPeerConfiguration config = new NetPeerConfiguration("gamajama");
     config.MaximumConnections = 100;
     config.UseMessageRecycling = true;
     config.Port = 14240;
     config.AcceptIncomingConnections = true;
     config.EnableMessageType(NetIncomingMessageType.DiscoveryResponse);
     config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
     config.EnableMessageType(NetIncomingMessageType.StatusChanged);
     config.EnableMessageType(NetIncomingMessageType.ErrorMessage);
     config.EnableMessageType(NetIncomingMessageType.DebugMessage);
     config.EnableMessageType(NetIncomingMessageType.VerboseDebugMessage);
     config.EnableMessageType(NetIncomingMessageType.Data);
     s_server = new NetServer(config);
     s_server.RegisterReceivedCallback(new SendOrPostCallback(getData));
     s_server.Start();
 }
Beispiel #7
0
        public static void Main(string[] args)
        {
            Console.WriteLine("[SERVER] Testing Lidgren-Network-v3...");

            NetPeerConfiguration serverConfig = new NetPeerConfiguration("test");
            serverConfig.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
            serverConfig.EnableMessageType(NetIncomingMessageType.Data);
            serverConfig.MaximumConnections = 32;
            serverConfig.Port = 80;
            NetServer server = new NetServer(serverConfig);
            server.Start();
            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
            var thread = new SendOrPostCallback(GotMessage);
            server.RegisterReceivedCallback(thread);
            while (true)
            {
                Console.ReadLine();
                //    NetIncomingMessage inc;
                //    while ((inc = server.ReadMessage()) != null)
                //    {

                //        switch (inc.MessageType)
                //        {
                //            case NetIncomingMessageType.DiscoveryRequest:

                //                // Create a response and write some example data to it
                //                NetOutgoingMessage response = server.CreateMessage();
                //                response.Write(" Connected to: the person right next to you");

                //                // Send the response to the sender of the request
                //                server.SendDiscoveryResponse(response, inc.SenderEndPoint);
                //                break;
                //            case NetIncomingMessageType.Data:

                //                Console.WriteLine(inc.ReadString());
                //                break;
                //        }
                //    }

            }
        }
Beispiel #8
0
        static void Main(string[] args)
        {
            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
            players = new List<Player>();
            Console.WriteLine("This is the Server");//This is the server
            Config = new NetPeerConfiguration("DND Server");//use app id to recognize
            Console.WriteLine("Server configuration created.");
            //server and clients per to make sure they are the same on the client and server
            Config.Port = _SERVERPORT;//Port
            ///enables connection approval message type.  In Lidgren all messages are split into message types
            ///so you can ignor some or all of them.
            Config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
            Server = new NetServer(Config); //Intialize with the config
            Console.WriteLine("Server socket initialized.");
            Server.RegisterReceivedCallback(new SendOrPostCallback(RecieveData));
            //This will call the recieve data callback whenever the server recieves data
            //from a client in a separate thread
            Server.Start();//Start the server
            Console.WriteLine("Server Started");
            //~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
            //An example input manager to get respont on console
            new Thread(new ThreadStart(delegate
                {
                    Console.WriteLine("Checking for input");
                    string input;

                    while ((input = Console.ReadLine()) != null)
                    {
                        string[] prms = input.Split(' ');//params for the input

                        switch (prms[0])//The first param is the command name
                        {
                            default:
                                break;

                        }

                    }
                })).Start();
            //END INPUT MANAGEMENT
        }
Beispiel #9
0
        public static void Main(string[] args)
        {
            Console.WriteLine("[SERVER] Testing Lidgren-Network-v3...");
            NetPeerConfiguration serverConfig = new NetPeerConfiguration("test");
            serverConfig.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
            serverConfig.MaximumConnections = 32;
            serverConfig.Port = 12345;
            NetServer server = new NetServer(serverConfig);
            server.Start();

            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
            server.RegisterReceivedCallback(new SendOrPostCallback(GotMessage));

            while(true) {
                string msg = Console.ReadLine();

                NetOutgoingMessage sendMsg = server.CreateMessage();
                sendMsg.Write("[SERVER] " + msg);

                server.SendToAll(sendMsg, NetDeliveryMethod.ReliableOrdered);
            }
        }
Beispiel #10
0
        public void StartServer()
        {
            players = new List<PlayerObject>();
            server = new NetServer(config);
            server.RegisterReceivedCallback(new SendOrPostCallback(HandleMessages));
            server.Start();
            Console.WriteLine(" Crab Battle server open for business on Port: "+config.Port);
            Console.WriteLine(" ConnectionTimeout "+config.ConnectionTimeout+" PingInterval "+config.PingInterval);
            Console.WriteLine(" Max number of players is: "+config.MaximumConnections);

            t1 = new Thread(new ThreadStart(RunGameLoop));
            t1.Name = "Game Loop Thread";
            t1.Start();
            Thread.Sleep(500);
            // Replaced by RegisterReceivedCallback a.k.a HandleMessages
            /*
            t2 = new Thread(new ThreadStart(MessageProcessor));
            t2.Name = "Message Loop Thread";
            t2.Start();
            */
        }
Beispiel #11
0
        public void Run()
        {
            bool running = true;

            Console.WriteLine("Backup Remote");
            Console.Write("Master key: ");

            string key = "";
            ConsoleKeyInfo info;

            do
            {
                info = Console.ReadKey(true);

                if (info.Key != ConsoleKey.Backspace && info.Key != ConsoleKey.Enter)
                {
                    key += info.KeyChar;
                    Console.Write("*");
                }
                else if (info.Key == ConsoleKey.Backspace && key.Length > 0)
                {
                    key = key.Substring(0, key.Length - 1);
                    Console.Write("\b \b");
                }
            }
            while (info.Key != ConsoleKey.Enter);

            keyHash = GetHash(key);
            key = string.Empty;

            Console.WriteLine();
            Console.Write("Backup directory: ");

            backupDir = Console.ReadLine();

            if (!Directory.Exists(backupDir))
            {
                Console.WriteLine("Directory doesn't exist");
                return;
            }

            Console.WriteLine("Initializing...");

            Command.Register("close", a => running = false);
            Command.Register("manifest", a =>
            {
                if (a.Length == 0)
                {
                    Console.WriteLine(targetManager.GetManifestJSON());
                    return;
                }

                if (a[0] == "save")
                {
                    Console.WriteLine("Forced manifest save");
                    targetManager.SaveManifest();
                }
            });

            targetManager = new TargetManager(backupDir);

            NetPeerConfiguration cfg = new NetPeerConfiguration("BackupUtil");
            cfg.Port = 6969;

            cfg.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
            cfg.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);

            SynchronizationContext sync = new SynchronizationContext();
            SynchronizationContext.SetSynchronizationContext(sync);

            server = new NetServer(cfg);
            server.RegisterReceivedCallback(new SendOrPostCallback(MessageReceived), sync);
            server.Start();

            Console.WriteLine("Initialized");

            string line;
            while (running)
            {
                line = Console.ReadLine();

                string[] lineArgs = line.Split(' ');
                if (!Command.Run(lineArgs[0], lineArgs.Skip(1).ToArray()))
                    Console.WriteLine("Invalid command");
            }

            Console.WriteLine("Closing...");

            server.Shutdown("bye"); // TODO: figure out why client doesn't receive the message that the server is shut down
        }
Beispiel #12
0
 public Server()
 {
     NetPeerConfiguration cfg = new NetPeerConfiguration("bandit");
     cfg.Port = 5635;
     server = new NetServer(cfg);
     server.RegisterReceivedCallback(new SendOrPostCallback(GotLidgrenMessage), new SynchronizationContext());
     gameStarted = DateTime.Now;
     lootTimer = new Timer(o => PlaceLoot(), null, 0, LOOT_INTERVAL);
     timeTimer = new Timer(o => UpdateTime(), null, 0, TIME_INTERVAL);
     frameTimer = new Timer(o => EveryFrame(), null, 0, FRAME_INTERVAL);
 }
Beispiel #13
0
        static void Main(string[] args)
        {
            Console.WriteLine("Akanonda Server");
            Console.WriteLine("---------------");

            // NetServer START
            NetPeerConfiguration netconfig = new NetPeerConfiguration("game");
            netconfig.MaximumConnections = settings.MaxConnections;
            netconfig.Port = settings.GamePort;
            netserver = new NetServer(netconfig);

            NetPeerConfiguration config = new NetPeerConfiguration("chat");
            config.MaximumConnections = 100;
            config.Port = settings.ChatPort;
            chatServer = new NetServer(config);

            SurvivalTimer = new System.Timers.Timer();
            SurvivalTimer.Interval = 1000;
            SurvivalTimer.Elapsed += new ElapsedEventHandler(gameSecondTick);
            SurvivalTimer.Start();

            if (SynchronizationContext.Current == null)
                SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());

            netserver.RegisterReceivedCallback(new SendOrPostCallback(ReceiveData));

            netserver.Start();
            StartChat();

            game = Game.Instance;

            gameSpeedTimer = new System.Timers.Timer(settings.GameSpeed);
            gameSpeedTimer.Elapsed += new ElapsedEventHandler(gameSpeedTimer_Elapsed);
            gameSpeedTimer.Enabled = true;

            Console.Write("Command: ");
            while (true)
            {
                string input = Console.ReadLine();
                switch (input)
                {
                    case "start":
                        break;
                    case "status":
                        Console.WriteLine(netserver.ConnectionsCount);
                        break;
                    case "exit":
                        netserver.Shutdown("Exit");
                        Environment.Exit(0);
                        break;
                    case "stop Chat":
                        StopChat();
                        Console.WriteLine("Chat stopped");
                        break;
                    case "start Chat":
                        StartChat();
                        Console.WriteLine("Chat started");
                        break;
                    case "kick Player":
                        Console.WriteLine("Enter Player name:");
                        string playerToKick = Console.ReadLine();
                        Player playerToFind = game.PLayerList.Find(item => item.name == playerToKick);
                        if (playerToFind != null)
                        {
                            game.addDeadRemoveLivingPlayer(playerToFind.guid);
                        }
                        break;
                    default:
                        Console.WriteLine("Command not found.");
                        break;
                }
                Console.Write("Command: ");
            }
        }
Beispiel #14
0
        static void Main(string[] args)
        {
            SynchronizationContext.SetSynchronizationContext(new SynchronizationContext());
            Console.WriteLine("This is the server");
            Players = new List<Player>();
            Config = new NetPeerConfiguration("MyGame");
            Console.WriteLine("Server configuration created.");
            Config.Port = 7777;
            Config.EnableMessageType(NetIncomingMessageType.ConnectionApproval);
            Server = new NetServer(Config);
            Console.WriteLine("Server socket initialized");
            Server.RegisterReceivedCallback(new SendOrPostCallback(ReceiveData));
            Server.Start();
            Console.WriteLine("Server started");

            new Thread(new ThreadStart(delegate
                {
                    string input;

                    while ((input = Console.ReadLine()) != null)
                    {
                        Console.WriteLine("New Input.");
                        string[] prms = input.Split(' ');

                        switch (prms[0])
                        {
                            //No commands on server as of now
                        }
                    }
                })).Start();
        }