Exemplo n.º 1
0
        static void Main(string[] args)
        {
            NetPeerConfiguration config = new NetPeerConfiguration("LidgrenTestServer");
            config.Port = 14242;
            config.MaximumConnections = 200;

            NetServer server = new NetServer(config);

            server.Start();

            NetIncomingMessage msg;
            while(true)
            {
                if((msg = server.ReadMessage()) != null)
                {
                    Console.WriteLine(msg.ReadString());
                    server.Recycle(msg);
                }
                Thread.Sleep(20);
            }
        }
Exemplo n.º 2
0
		/// <summary>
		/// 
		/// </summary>
		/// <param name="message"></param>
		void DispatchIM ( GameTime gameTime, SnapshotQueue queue, NetServer server )
		{
			NetIncomingMessage msg;
			while ((msg = server.ReadMessage()) != null)
			{
				switch (msg.MessageType)
				{
					case NetIncomingMessageType.VerboseDebugMessage:Log.Debug	("SV Net: " + msg.ReadString()); break;
					case NetIncomingMessageType.DebugMessage:		Log.Verbose	("SV Net: " + msg.ReadString()); break;
					case NetIncomingMessageType.WarningMessage:		Log.Warning	("SV Net: " + msg.ReadString()); break;
					case NetIncomingMessageType.ErrorMessage:		Log.Error	("SV Net: " + msg.ReadString()); break;

					case NetIncomingMessageType.ConnectionLatencyUpdated:
						if (Game.Network.ShowLatency) {
							float latency = msg.ReadFloat();
							Log.Verbose("...SV ping - {0} {1,6:0.00} ms", msg.SenderEndPoint, (latency*1000) );
						}

						break;

					case NetIncomingMessageType.DiscoveryRequest:
						Log.Message("Discovery request from {0}", msg.SenderEndPoint.ToString() );
						var response = server.CreateMessage( ServerInfo() );
						server.SendDiscoveryResponse( response, msg.SenderEndPoint );

						break;

					case NetIncomingMessageType.ConnectionApproval:
						
						var userGuid	=	msg.SenderConnection.GetHailGuid();
						var userInfo	=	msg.SenderConnection.GetHailUserInfo();
						var reason		=	"";
						var approve		=	ApproveClient( userGuid, userInfo, out reason );

						if (approve) {	
							msg.SenderConnection.Approve( server.CreateMessage( ServerInfo() ) );
						} else {
							msg.SenderConnection.Deny( reason );
						}

						break;

					case NetIncomingMessageType.StatusChanged:		
						DispatchStatusChange( msg );
						break;
					
					case NetIncomingMessageType.Data:
						DispatchDataIM( gameTime, queue, msg );
						break;
					
					default:
						Log.Warning("SV: Unhandled type: " + msg.MessageType);
						break;
				}
				server.Recycle(msg);
			}		
		}
Exemplo n.º 3
0
        static void Main(string[] args)
        {
            var config = new NetPeerConfiguration("ConquerLeague")
            {
                Port = 47410
            };

            config.EnableMessageType(NetIncomingMessageType.DiscoveryRequest);
            server = new NetServer(config);
            server.Start();

            SessionManager sessionManager = new SessionManager();

            while (true)
            {
                NetIncomingMessage message;
                while ((message = server.ReadMessage()) != null)
                {
                    switch (message.MessageType)
                    {
                    case NetIncomingMessageType.DiscoveryRequest:
                        NetOutgoingMessage response = server.CreateMessage();           // Create a response and write some example data to it
                        response.Write("ConquerLeagueServer");
                        server.SendDiscoveryResponse(response, message.SenderEndPoint); // Send the response to the sender of the request
                        break;

                    case NetIncomingMessageType.Data:
                        var dataLength = message.ReadInt32();
                        var data       = message.ReadBytes(dataLength);
                        sessionManager.ForwardMessageToSession(message.SenderConnection, dataLength, data);
                        break;

                    case NetIncomingMessageType.StatusChanged:
                        Console.WriteLine(message.SenderConnection.Status);
                        switch (message.SenderConnection.Status)
                        {
                        case NetConnectionStatus.Connected:
                            Console.WriteLine("Client " + message.SenderConnection.RemoteEndPoint.ToString() + " connected!");
                            sessionManager.AddPlayerToMatchmaking(message.SenderConnection);
                            break;

                        case NetConnectionStatus.RespondedConnect:
                            Console.WriteLine(message.SenderConnection.Status.ToString());
                            break;

                        default:
                            Console.WriteLine("Unhandled status change with type: " + message.SenderConnection.Status.ToString());
                            break;
                        }

                        break;

                    case NetIncomingMessageType.ConnectionApproval:
                        message.SenderConnection.Approve();
                        break;

                    case NetIncomingMessageType.DebugMessage:
                        Console.WriteLine(message.ReadString());
                        break;

                    case NetIncomingMessageType.WarningMessage:
                        Console.WriteLine("Warning: " + message.ReadString());
                        break;

                    default:
                        Console.WriteLine("unhandled message with type: " + message.MessageType);
                        break;
                    }

                    server.Recycle(message);
                }
            }
        }