示例#1
0
文件: Client.cs 项目: MyEyes/Igorr
 public Client(NetConnection connection, string name, ProtocolHelper ph)
 {
     id = idcounter++;
     _clientConnection = connection;
     _name = name;
     ProtocolHelper = ph;
 }
示例#2
0
文件: Server.cs 项目: MyEyes/Igorr
        //ObjectManager manager;
        public Server()
        {
            LuaVM.DoFile("settings.lua");

            string Content = LuaVM.GetValue<string>("Content", "Content");
            Modules.ModuleManager.SetContentDir(Content);
            Modules.ModuleManager.LoadAllModules();

            Management.ClientInfoInterface.LoadInfos();
            LuaVM.Register("GetInfo", null, typeof(Management.ClientInfoInterface).GetMethod("GetValue").GetBaseDefinition());
            LuaVM.Register("SetInfo", null, typeof(Management.ClientInfoInterface).GetMethod("SetValue").GetBaseDefinition());
            LuaVM.Register("SetGlobal", null, typeof(GlobalTriggers).GetMethod("SetTriggerValue").GetBaseDefinition());
            LuaVM.Register("GetGlobal", null, typeof(GlobalTriggers).GetMethod("GetTriggerValue").GetBaseDefinition());

            NetPeerConfiguration config = new NetPeerConfiguration("IGORR");
            config.Port = LuaVM.GetValue<int>("port", 5445);
            //config.SimulatedMinimumLatency = 2f;
            //config.SimulatedRandomLatency = 1f;
            //config.LocalAddress = new System.Net.IPAddress(new byte[] { 127, 0, 0, 1 });
            connection = new NetServer(config);
            connection.Start();
            _protocolHelper = new ProtocolHelper(connection);
            ProtocolHelper.RegisterMessageHandler(MessageTypes.Chat, new MessageHandler(HandleChat));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.Position, new MessageHandler(HandlePosition));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.Leave, new MessageHandler(HandleLeave));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.Join, new MessageHandler(HandleJoin));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.Attack, new MessageHandler(HandleAttack));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.Interact, new MessageHandler(HandleInteract));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.MoveItem, new MessageHandler(HandleMoveItem));
            _clientids = new Dictionary<long, int>();
            _clients = new Dictionary<int, Client>();
            _connections = new List<NetConnection>();
            receiveThread = new Thread(new ThreadStart(ReceiveMessage));
            receiveThread.Start();
            EventObject.server = this;
            LogicHandler.SetUp(this);
            _startTime = DateTime.Now;
            _lastTime = DateTime.Now;
        }
示例#3
0
        public static void Start()
        {
            NetPeerConfiguration config = new NetPeerConfiguration("IGORR");
            //config.SimulatedMinimumLatency = 0.5f;
            //config.SimulatedRandomLatency = 0.5f;
            connection = new NetClient(config);
            connection.Start();
            connection.Connect(Settings.ServerAddress, 5445);
            //connection.Connect("firzen.dyndns.org", 5445);
            System.Threading.SpinWait.SpinUntil(new Func<bool>(delegate { return connection.ServerConnection != null; }), 5000);
            if (connection.ServerConnection == null)
            {
                MessageBox.Show("Could not connect to server.\nAddress: " + Settings.ServerAddress, "Connection Error");
                //Thread.CurrentThread.Abort();
                return;
            }

            _protocolHelper = new ProtocolHelper(connection);
            ProtocolHelper.RegisterMessageHandler(MessageTypes.Spawn, new MessageHandler(HandleSpawn));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.SpawnAttack, new MessageHandler(HandleSpawnAttack));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.AssignPlayer, new MessageHandler(HandleAssignPlayer));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.Position, new MessageHandler(HandlePosition));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.DeSpawn, new MessageHandler(HandleDespawn));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.Pickup, new MessageHandler(HandlePickup));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.Kill, new MessageHandler(HandleKill));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.Damage, new MessageHandler(HandleDamage));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.SetAnimation, new MessageHandler(HandleSetAnimation));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.SetGlow, new MessageHandler(HandleSetGlow));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.ChangeTile, new MessageHandler(HandleChangeTile));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.ChangeMap, new MessageHandler(HandleChangeMap));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.Play, new MessageHandler(HandlePlay));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.Shadow, new MessageHandler(HandleShadows));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.SetHP, new MessageHandler(HandleSetHP));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.PlayerInfo, new MessageHandler(HandlePlayerInfo));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.ExpMessage, new MessageHandler(HandleExp));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.Knockback, new MessageHandler(HandleKnockback));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.ObjectInfo, new MessageHandler(HandleObjectInfo));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.DoEffect, new MessageHandler(HandleDoEffect));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.Chat, new MessageHandler(HandleChat));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.Interact, new MessageHandler(HandleInteract));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.Container, new MessageHandler(HandleContainer));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.BodyConfiguration, new MessageHandler(HandleBodyConfiguration));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.AttachAnimation, new MessageHandler(HandleAttachAnimation));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.Stun, new MessageHandler(HandleStun));
            ProtocolHelper.RegisterMessageHandler(MessageTypes.MoveItem, new MessageHandler(HandleMoveItem));
            receiveThread = new Thread(new ThreadStart(Receive));
            receiveThread.Start();
            System.Threading.SpinWait.SpinUntil(new Func<bool>(delegate { return connection.ServerConnection.Status == NetConnectionStatus.Connected; }), 5000);
            JoinMessage m = (JoinMessage)ProtocolHelper.NewMessage(MessageTypes.Join);
            m.Name = Settings.LoginName;
            m.Password = Settings.LoginPassword;
            m.Encode();
            SendReliable(m);
            _started = true;
        }