Esempio n. 1
0
 public ServerSocket(TcpClient client, Server server) : base(new DeadLog())
 {
     client.Client.SendTimeout = 4000;
     this.Setup(client,new ServerMessageProcessor());
     Server = server;
     LastPingTime = DateTime.Now;
 }
Esempio n. 2
0
 public void Start()
 {
     Log.Info("Starting");
     this.OnStart(null);
     Server = new Server(GameStateEngine.GetContext(), Program.BroadcastPort);
     Server.OnStop += (sender, args) => { if (!StopCalled) this.Stop(); };
     Log.Info("Started");
 }
Esempio n. 3
0
 public void Start()
 {
     Log.Info("Starting");
     this.OnStart(null);
     if(!Program.Local)
         SasManagerServiceClient.GetContext().Start();
     Server = new Server(GameStateEngine.GetContext());
     Server.OnStop += (sender, args) => { if (!StopCalled) this.Stop(); };
     Log.Info("Started");
 }
Esempio n. 4
0
 // Handle a binary message
 internal void ReceiveMessage(byte[] data, TcpClient sender,Server.Connection con)
 {
     // Check if this is the first message received
     if(!clients.ContainsKey(sender))
     {
         // A new connection must always start with a <Hello> xml message, refuse the connection
         sender.GetStream().Close(); return;
     }
     // Set the sender field
     this.sender = sender;
     this.Connection = con;
     // Parse and handle the message
     binParser.Parse(data);
 }
Esempio n. 5
0
 // Show the management GUI
 //        internal void ShowGUI(System.Windows.Forms.Form parent)
 //        {
 //            ManagementForm cf = new ManagementForm(clients);
 //            cf.ShowDialog(parent);
 //        }
 // Handle an XML message
 internal void ReceiveMessage(string msg, TcpClient sender, Server.Connection con)
 {
     // Check if this is the first message received
     if(!clients.ContainsKey(sender))
     {
         // A new connection must always start with a <Hello> message.
         if(!msg.StartsWith("<Hello>", StringComparison.Ordinal))
         {
             // Refuse the connection
             sender.GetStream().Close(); return;
         }
     }
     // Set the sender field
     this.sender = sender;
     this.Connection = con;
     // Parse and handle the message
     xmlParser.Parse(msg);
 }
Esempio n. 6
0
            private int _packetPos; // Current position in the packet buffer

            #endregion Fields

            #region Constructors

            // C'tor
            internal Connection(Server server, TcpClient client)
            {
                // Init fields
                _server = server;
                Client = client;
                //Start ping thread
                _pingThread = new Thread(DoPing);
                _lastPing = DateTime.Now;
                _pingThread.Start();
                // Start reading
                client.GetStream().BeginRead(_buffer, 0, 512, Receive, null);
            }
Esempio n. 7
0
 // Show the management GUI
 //        internal void ShowGUI(System.Windows.Forms.Form parent)
 //        {
 //            ManagementForm cf = new ManagementForm(clients);
 //            cf.ShowDialog(parent);
 //        }
 // Handle a Binary message
 internal void ReceiveMessage(byte[] data, TcpClient lSender, Server.Connection con)
 {
     // Check if this is the first message received
     if (!_clients.ContainsKey(lSender))
     {
         // A new connection must always start with a hello message, refuse the connection
         if (data[4] != (byte)2)
         {
             lSender.GetStream().Close();
             return;
         }
     }
     // Set the lSender field
     _sender = lSender;
     _connection = con;
     // Parse and handle the message
     _binParser.Parse(data);
 }
Esempio n. 8
0
 public static void StopGame()
 {
     Client.Disconnect(); Client = null;
     if (Server != null)
     { Server.Stop(); Server = null; }
     Game.End(); Game = null;
     Dispatcher = null;
     Database.Close();
     IsGameRunning = false;
 }