示例#1
0
        public Program()
        {
            NetAppConfiguration myConfig = new NetAppConfiguration("MMO Mahjong", 14242);

            NetLog log = new NetLog();

            NetClient Client = new NetClient(myConfig, log);

            Client.Connect("localhost", 14242);                                           // takes IP number or hostnameHow to detect connects/disconnects
            Client.StatusChanged += new EventHandler <NetStatusEventArgs>(StatusChanged); // to track connect/disconnect etc

            bool keepGoing = true;

            while (keepGoing)
            {
                Client.Heartbeat();

                NetMessage msg;
                while ((msg = Client.ReadMessage()) != null)
                {
                    string str = msg.ReadString(); // <- for example
                    System.Console.WriteLine("You got a packet containing: " + str);
                    Thread.Sleep(1);
                }
            }
        }
示例#2
0
        MMOServer(int port)
        {
            m_plugin = new Plugin(Environment.CurrentDirectory);

            Init();
            NetAppConfiguration config = new NetAppConfiguration("MMO Mahjong", port);

            config.MaximumConnections = 128;
            config.Port       = port;
            config.ServerName = Environment.MachineName + " server";

            m_log             = new NetLog();
            m_log.IgnoreTypes = NetLogEntryTypes.None;
            m_log.LogEvent   += new EventHandler <NetLogEventArgs>(OnLogEvent);

            Server = new NetServer(config, m_log);
            Server.StatusChanged += new EventHandler <NetStatusEventArgs>(OnStatusChange);

            Server.ConnectionRequest += new EventHandler <NetConnectRequestEventArgs>(OnConnectionRequest);

            while (true)
            {
                Server.Heartbeat();

                NetMessage msg;
                while ((msg = Server.ReadMessage()) != null)
                {
                    HandleMessage(msg);
                }

                System.Threading.Thread.Sleep(1);
            }
        }
示例#3
0
        public IPlayer(String dns, int port)
        {
            NetAppConfiguration myConfig = new NetAppConfiguration("MMO Mahjong");

            m_log = new NetLog();
            Init();
            m_client = new NetClient(myConfig, m_log);
            m_client.Connect(dns, port);
            m_client.StatusChanged += new EventHandler <NetStatusEventArgs>(StatusChanged);
            Application.Idle       += new EventHandler(ApplicationLoop);
        }
示例#4
0
        /// <summary>
        /// Initializes the network engine.
        /// </summary>
        /// <param name="strName">The name of the user</param>
        public SpiderClient(String strName)
        {
            spiderName               = strName;
            spiderConfig             = new NetAppConfiguration("ymfas", DEFAULT_PORT);
            spiderLog                = new NetLog();
            spiderLog.OutputFileName = "YMFAS Net Log (Port " + DEFAULT_PORT + ").html";
            localSessionQueue        = new Queue(50);
            messageQueue             = new Queue(50);
            disconnectQueue          = new Queue(50);

            spiderNet = new NetClient(spiderConfig, spiderLog);
        }
示例#5
0
        /// <summary>
        /// Initializes the network engine.
        /// </summary>
        /// <param name="type">Client or Server</param>
        /// <param name="strName">The name of the user</param>
        public SpiderServer(String strName)
        {
            spiderName               = strName;
            spiderConfig             = new NetAppConfiguration("ymfas", DEFAULT_PORT);
            spiderLog                = new NetLog();
            spiderLog.OutputFileName = "YMFAS Net Log (Port 30803).html";
            messageQueue             = new Queue(50);
            disconnectQueue          = new Queue(50);

            spiderConfig.MaximumConnections = MAX_CONNECTIONS;
            spiderConfig.ServerName         = spiderName + "'s Game";
            spiderNet = new NetServer(spiderConfig, spiderLog);
            spiderNet.StatusChanged += new EventHandler <NetStatusEventArgs>(SpiderNet_StatusChangedHandler);
            clients = new ArrayList();
        }
示例#6
0
 public void ClientClicked()
 {
     _nac = new NetAppConfiguration("ZombieMadness");
     _log = new NetLog();
     //Set it up so that the Log Igores Nothing
     _log.IgnoreTypes = NetLogEntryTypes.None;
     //We want to Output to file, this shows how to do so.
     _log.IsOutputToFileEnabled = true;
     //If we output to a file we need to big a name, this was simple
     _log.OutputFileName    = "Client.html";
     _client                = new NetClient(_nac, _log);
     _client.StatusChanged += new EventHandler <NetStatusEventArgs>(client_StatusChanged);
     _client.Configuration.ApplicationIdentifier = "ZombieMadness";
     _client.ServerDiscovered += new EventHandler <NetServerDiscoveredEventArgs>(_client_ServerDiscovered);
     _client.DiscoverKnownServer(IP, 26530);
 }
示例#7
0
 public void HostClicked()
 {
     //This sets up the configuration, when your setting the config up for server we pick the application name and the port that the server
     //will bound to when we create it
     _nac = new NetAppConfiguration("ZombieMadness", 26530);
     //set the maximum connects, im not sure the biggest number aloud at this moment in time
     _nac.MaximumConnections = 32;
     //This is used for somthing later on in the tutorials, where the client can discover hosts.
     _nac.ServerName = "ZombieMadness!";
     //Initiate the log
     _log = new NetLog();
     //Create the server using the Log and the Configuration, this will bound the port on the computer.
     _server = new NetServer(_nac, _log);
     // Add an Event Handler for when a client connects or disconnects.
     _server.StatusChanged += new EventHandler <NetStatusEventArgs>(server_StatusChanged);
 }