コード例 #1
0
        public static CashItem[] GetCashItem(SyncReceiver sync, int server, int id)
        {
            var packet = sync.CreateIPC(IPC.GetCashItemList);

            packet.Write((byte)server);
            packet.Write(id);

            sync.Send(packet);


            var recv = sync.ReadIPC();

            if (recv == null)
            {
                return(null);
            }

            var itens = recv.ReadInt32();

            var ItemList = new CashItem[itens];

            for (int i = 0; i < itens; i++)
            {
                ItemList[i]          = new CashItem();
                ItemList[i].ID       = recv.ReadInt32();
                ItemList[i].itemid   = recv.ReadInt32();
                ItemList[i].itemopt  = recv.ReadBytes(8);
                ItemList[i].itemopt2 = recv.ReadInt32();
                ItemList[i].duration = recv.ReadInt32();
            }
            return(ItemList);
        }
コード例 #2
0
 public static void Remove(Dictionary <ulong, ClientHandler> clients, SyncReceiver syncServer, EventHandler events, ulong magic, ClientHandler client, System.Net.EndPoint ip, int AccID)
 {
     try
     {
         foreach (ClientHandler cli in clients.Values)
         {
             if (cli.RemoteEndPoint == null)
             {
                 clients.Remove((ulong)cli.Metadata["magic"]);
                 Authentication.GetUser(syncServer, (ulong)cli.Metadata["magic"]);
                 client.Disconnect();
             }
             else if (cli.RemoteEndPoint == ip)
             {
                 clients.Remove(magic);
                 Authentication.GetUser(syncServer, magic);
                 events.ClientDisconnected(events, client);
             }
         }
     }
     catch (Exception)
     {
         Log.Notice("Account {0} already removed", AccID);
     }
 }
コード例 #3
0
        public static DeleteCharacterStatus DeleteCharacter(SyncReceiver sync, int server, int id, int slot)
        {
            var packet = sync.CreateIPC(IPC.DeleteCharacter);

            packet.Write((byte)server);
            packet.Write(id);
            packet.Write((byte)slot);

            sync.Send(packet);

            var recv = sync.ReadIPC();

            if (recv == null)
            {
                return(DeleteCharacterStatus.DBError);
            }

            var status = (DeleteCharacterStatus)recv.ReadByte();

            switch (status)
            {
            case DeleteCharacterStatus.Success: return(DeleteCharacterStatus.Success);

            default: return(DeleteCharacterStatus.DBError);
            }
        }
コード例 #4
0
        public static AccountData FetchAccount(SyncReceiver sync, string name, string pass)
        {
            var packet = sync.CreateIPC(IPC.FetchAccount);

            packet.Write(name);
            packet.Write(pass);
            sync.Send(packet);

            var recv = sync.ReadIPC();

            AccountData data = new AccountData();

            data.id     = -1;
            data.name   = name;
            data.status = AuthStatus.Unverified;
            data.online = false;

            if (recv == null)
            {
                return(data);
            }

            data.id     = recv.ReadInt32();                 // we should change to uint; and use "id = 0" for invalid/non exist account
            data.status = (AuthStatus)recv.ReadByte();
            data.online = recv.ReadBoolean();

            return(data);
        }
コード例 #5
0
ファイル: Authentication.cs プロジェクト: lKnuckles/minerva
        public static AccountData FetchAccount(SyncReceiver sync, string name, string pass)
        {
            var packet = sync.CreateIPC(IPC.FetchAccount);

            packet.Write(name);
            packet.Write(pass);
            sync.Send(packet);

            var recv = sync.ReadIPC();

            AccountData data = new AccountData();

            data.id     = -1;
            data.name   = name;
            data.status = AuthStatus.Unverified;

            if (recv == null)
            {
                return(data);
            }

            data.id     = recv.ReadInt32();
            data.status = (AuthStatus)recv.ReadByte();

            return(data);
        }
コード例 #6
0
        public static void RemoveSubPass(SyncReceiver sync, int id)
        {
            var packet = sync.CreateIPC(IPC.RemoveSubPass);

            packet.Write(id);

            sync.Send(packet);
        }
コード例 #7
0
        public static void UpdateOnline(SyncReceiver sync, int id, bool online)
        {
            var packet = sync.CreateIPC(IPC.UpdateOnline);

            packet.Write(id);
            packet.Write(online);

            sync.Send(packet);
        }
コード例 #8
0
        public static void AddUser(SyncReceiver sync, ulong key, int id)
        {
            var packet = sync.CreateIPC(IPC.AddUser);

            packet.Write(key);
            packet.Write(id);

            sync.Send(packet);
        }
コード例 #9
0
        public static void SetSubPassTime(SyncReceiver sync, int id, int time)
        {
            var packet = sync.CreateIPC(IPC.SetSubPassTime);

            packet.Write(id);
            packet.Write((byte)time);

            sync.Send(packet);
        }
コード例 #10
0
        public static void SetCashItem(SyncReceiver sync, int server, int ID)
        {
            var packet = sync.CreateIPC(IPC.SetCashItem);

            packet.Write((byte)server);
            packet.Write(ID);

            sync.Send(packet);
        }
コード例 #11
0
        public static void SetSlotOrder(SyncReceiver sync, int server, int id, int order)
        {
            var packet = sync.CreateIPC(IPC.SetSlotOrder);

            packet.Write((byte)server);
            packet.Write(id);
            packet.Write(order);

            sync.Send(packet);
        }
コード例 #12
0
        public static void UpdateIPDate(SyncReceiver sync, int id, string ip, DateTime date)
        {
            var packet = sync.CreateIPC(IPC.UpdateIPDate);

            packet.Write(id);   // change to uint..?
            packet.Write(ip);   // ip should be uint
            packet.Write(date.ToBinary());

            sync.Send(packet);
        }
コード例 #13
0
ファイル: Server.cs プロジェクト: lKnuckles/minerva
        public Server()
        {
            Console.Title         = "Minerva Login Server";
            Console.CursorVisible = false;

            var start = Environment.TickCount;

            Util.Info.PrintLogo();
            Console.WriteLine();

            AppDomain.CurrentDomain.UnhandledException += UnhandledException;

            Log.Start("Login"); // Start logging service

            Log.Message("Registering events...", Log.DefaultFG);
            clients = new HashSet <ClientHandler>();
            events  = new EventHandler();
            events.OnClientDisconnect += (sender, client) => { Log.Notice("Client {0} disconnected from Login Server", client.RemoteEndPoint); clients.Remove(client); };
            events.OnError            += (sender, message) => Log.Error(message);
            events.OnReceivePacket    += (sender, e) => Log.Received(e.Name, e.Opcode, e.Length);
            events.OnSendPacket       += (sender, e) => Log.Sent(e.Name, e.Opcode, e.Length);

            Log.Message("Compiling and registering scripts...", Log.DefaultFG);
            scripts = new ScriptHandler();
            scripts.Concatenate("Events", new string[] { "mscorlib" });
            scripts.Run("Events");
            scripts.CreateInstance("Events");
            var result = scripts.Invoke("_init_", events);

            try
            {
                Log.Message("Reading configuration...", Log.DefaultFG);
                Configuration.Load();

                Log.Message("Registering packets...", Log.DefaultFG);
                packets = new PacketHandler("login", new PacketProtocol().GetType(), events);

                RSA.GenerateKeyPair();

                listener = new TcpListener(Configuration.IP, Configuration.Port);
                thread   = new Thread(Listen);
                thread.Start();

                syncServer = new SyncReceiver(Configuration.MasterIP, Configuration.MasterPort);

                Log.Notice("Minerva started in: {0} seconds", (Environment.TickCount - start) / 1000.0f);
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
                #if DEBUG
                throw e;
                #endif
            }
        }
コード例 #14
0
        public static void SetQuickSlots(SyncReceiver sync, int server, int id, int quickslot, int position)
        {
            var packet = sync.CreateIPC(IPC.SetQuickSlots);

            packet.Write((byte)server);
            packet.Write(id);
            packet.Write(quickslot);
            packet.Write(position);

            sync.Send(packet);
        }
コード例 #15
0
        public static void SetSubPass(SyncReceiver sync, int id, string subpw, int question, string answer)
        {
            var packet = sync.CreateIPC(IPC.SetSubPass);

            packet.Write(id);
            packet.Write(subpw);
            packet.Write((byte)question);
            packet.Write(answer);

            sync.Send(packet);
        }
コード例 #16
0
        public static void UpdateSkillPoints(SyncReceiver sync, int server, int charId, ushort skillid, ushort level, byte slot)
        {
            var packet = sync.CreateIPC(IPC.UpdateSkillPoints);

            packet.Write((byte)server);
            packet.Write(charId);
            packet.Write(skillid);
            packet.Write(level);
            packet.Write(slot);

            sync.Send(packet);
        }
コード例 #17
0
        public static void RegisterChannel(SyncReceiver sync, int server, int channel, int type, uint ip, int port, int maxPlayers)
        {
            var packet = sync.CreateIPC(IPC.RegisterChannel);

            packet.Write((byte)server);
            packet.Write((byte)channel);
            packet.Write(type);
            packet.Write(ip);
            packet.Write((ushort)port);
            packet.Write((ushort)maxPlayers);

            sync.Send(packet);
        }
コード例 #18
0
        public static void UpdatePosition(SyncReceiver sync, int server, int id, byte slot, byte map, byte x, byte y)
        {
            var packet = sync.CreateIPC(IPC.UpdatePosition);

            packet.Write((byte)server);
            packet.Write(id);
            packet.Write(slot);
            packet.Write(map);
            packet.Write(x);
            packet.Write(y);

            sync.Send(packet);
        }
コード例 #19
0
        public static void UpdateStatPoints(SyncReceiver sync, int server, int id, int str, int intel, int dex, int points)
        {
            var packet = sync.CreateIPC(IPC.UpdateStatPoints);

            packet.Write((byte)server);
            packet.Write(id);
            packet.Write(str);
            packet.Write(intel);
            packet.Write(dex);
            packet.Write(points);

            sync.Send(packet);
        }
コード例 #20
0
        public static Character[] GetCharacters(SyncReceiver sync, int server, int id)
        {
            var packet = sync.CreateIPC(IPC.GetCharacterList);

            packet.Write((byte)server);
            packet.Write(id);

            sync.Send(packet);

            var recv = sync.ReadIPC();

            if (recv == null)
            {
                return(null);
            }

            var num      = recv.ReadInt32();
            var charList = new Character[num];

            for (int i = 0; i < num; i++)
            {
                charList[i]         = new Character();
                charList[i].account = id;
                charList[i].id      = recv.ReadInt32();
                charList[i].slot    = recv.ReadByte();
                charList[i].name    = recv.ReadString();
                charList[i].level   = recv.ReadUInt32();
                charList[i]._class  = recv.ReadByte();
                charList[i].face    = recv.ReadByte();
                charList[i].hair    = recv.ReadByte();
                charList[i].colour  = recv.ReadByte();
                charList[i].gender  = recv.ReadBoolean();
                charList[i].map     = recv.ReadByte();
                charList[i].x       = recv.ReadByte();
                charList[i].y       = recv.ReadByte();
                charList[i].created = DateTime.FromBinary(recv.ReadInt64());

                charList[i].equipment           = new Equipment();
                charList[i].equipment.head      = recv.ReadBytes(15);
                charList[i].equipment.body      = recv.ReadBytes(15);
                charList[i].equipment.hands     = recv.ReadBytes(15);
                charList[i].equipment.feet      = recv.ReadBytes(15);
                charList[i].equipment.righthand = recv.ReadBytes(15);
                charList[i].equipment.lefthand  = recv.ReadBytes(15);
                charList[i].equipment.back      = recv.ReadBytes(15);
            }

            return(charList);
        }
コード例 #21
0
ファイル: ServerList.cs プロジェクト: lKnuckles/minerva
        public static ServerData[] GetChannels(SyncReceiver sync)
        {
            var packet = sync.CreateIPC(IPC.ChannelList);

            sync.Send(packet);

            var recv = sync.ReadIPC();

            if (recv == null)
            {
                return(null);
            }

            var num = recv.ReadInt32();

            if (num <= 0)
            {
                return(null);
            }

            var serverList = new ServerData[num];

            for (var i = 0; i < num; i++)
            {
                var serverId      = recv.ReadInt32();
                var channelLength = recv.ReadInt32();

                if (serverId < 0)
                {
                    continue;
                }

                serverList[i] = new ServerData(serverId, channelLength);

                for (var j = 0; j < channelLength; j++)
                {
                    var id         = recv.ReadInt32();
                    var type       = recv.ReadInt32();
                    var ip         = recv.ReadUInt32();
                    var port       = recv.ReadInt16();
                    var maxPlayers = recv.ReadInt16();
                    var curPlayers = recv.ReadInt16();
                    serverList[i].channels[j] = new ChannelData(id, type, ip, port, maxPlayers, curPlayers);
                }
            }

            return(serverList);
        }
コード例 #22
0
        public static bool VerifyPassword(SyncReceiver sync, int id, string pass)
        {
            var packet = sync.CreateIPC(IPC.VerifyPassword);

            packet.Write(id);
            packet.Write(pass);
            sync.Send(packet);

            var recv = sync.ReadIPC();

            if (recv == null)
            {
                return(false);
            }

            var tmp = recv.ReadBoolean();

            return(tmp);
        }
コード例 #23
0
        public static bool GetSubpass(SyncReceiver sync, int id)
        {
            var packet = sync.CreateIPC(IPC.GetSubPass);

            packet.Write(id);

            sync.Send(packet);

            var recv = sync.ReadIPC();

            if (recv == null)
            {
                return(false);
            }

            var sub = recv.ReadBoolean();

            return(sub);
        }
コード例 #24
0
        public static int GetSubPassQuestion(SyncReceiver sync, int id)
        {
            var packet = sync.CreateIPC(IPC.GetSubPassQuestion);

            packet.Write(id);

            sync.Send(packet);

            var recv = sync.ReadIPC();

            if (recv == null)
            {
                return(-1);
            }

            var sub = recv.ReadByte();

            return(sub);
        }
コード例 #25
0
        public static int GetSlotOrder(SyncReceiver sync, int server, int id)
        {
            var packet = sync.CreateIPC(IPC.GetSlotOrder);

            packet.Write((byte)server);
            packet.Write(id);

            sync.Send(packet);

            var recv = sync.ReadIPC();

            if (recv == null)
            {
                return(-1);
            }

            var slotorder = recv.ReadInt32();

            return(slotorder);
        }
コード例 #26
0
ファイル: Authentication.cs プロジェクト: lKnuckles/minerva
        public static int GetUser(SyncReceiver sync, ulong key)
        {
            var id     = -1;
            var packet = sync.CreateIPC(IPC.GetUser);

            packet.Write(key);

            sync.Send(packet);

            var recv = sync.ReadIPC();

            if (recv == null)
            {
                return(id);
            }

            id = recv.ReadInt32();

            return(id);
        }
コード例 #27
0
        public static bool CheckSubPwAnswer(SyncReceiver sync, int id, string answer)
        {
            var packet = sync.CreateIPC(IPC.CheckSubPassAnswer);

            packet.Write(id);
            packet.Write(answer);

            sync.Send(packet);

            var recv = sync.ReadIPC();

            if (recv == null)
            {
                return(false);
            }

            var sub = recv.ReadBoolean();

            return(sub);
        }
コード例 #28
0
        public static CreateCharacterStatus CreateCharacter(SyncReceiver sync, int server, int id, byte slot, string name, byte _class, bool gender, byte face, byte hair, byte colour)
        {
            var packet = sync.CreateIPC(IPC.CreateCharacter);

            packet.Write((byte)server);
            packet.Write(id);
            packet.Write(slot);
            packet.Write(name);
            packet.Write(_class);
            packet.Write(gender);
            packet.Write(face);
            packet.Write(hair);
            packet.Write(colour);

            sync.Send(packet);

            var recv = sync.ReadIPC();

            if (recv == null)
            {
                return(CreateCharacterStatus.DBError);
            }

            var status = (CreateCharacterStatus)recv.ReadByte();

            switch (status)
            {
            case CreateCharacterStatus.NameInUse: return(CreateCharacterStatus.NameInUse);

            case CreateCharacterStatus.SlotInUse: return(CreateCharacterStatus.SlotInUse);

            case CreateCharacterStatus.Success: return(CreateCharacterStatus.Success);

            default: return(CreateCharacterStatus.DBError);
            }
        }
コード例 #29
0
ファイル: Server.cs プロジェクト: programmerzlp/Minerva
        public Server()
        {
            Console.Title         = "Minerva Login Server";
            Console.CursorVisible = false;

            int start = Environment.TickCount;

            Util.Info.PrintLogo();
            Console.WriteLine();
            Util.Info.PrintInfo();
            Console.WriteLine();

            AppDomain.CurrentDomain.UnhandledException += UnhandledException;

            Log.Start("Login"); // start logging service

            clients = new HashSet <ClientHandler>();

            Log.Message("Reading configuration...", Log.DefaultFG);
            conf = new Configuration();

            Log.Message("Registering events...", Log.DefaultFG);
            events = new EventHandler();

            events.OnClientDisconnect += (sender, client) =>
            {
                Log.Notice("Client {0} disconnected from Login Server", client.RemoteEndPoint);

                // temporary disabled
                //if (client.AccountID > 0 && syncServer != null)
                //    Authentication.UpdateOnline(syncServer, client.AccountID, false);

                clients.Remove(client);
            };

            events.OnError         += (sender, message) => Log.Error(message);
            events.OnReceivePacket += (sender, e) => Log.Received(e.Name, e.Opcode, e.Length);
            events.OnSendPacket    += (sender, e) => Log.Sent(e.Name, e.Opcode, e.Length);

            events.OnIPCReceivePacket += (sender, e) => Log.IPC_Received(e.Opcode, e.Length);
            events.OnIPCSendPacket    += (sender, e) => Log.IPC_Sent(e.Opcode, e.Length);

            Log.Message("Compiling and registering scripts...", Log.DefaultFG);
            scripts = new ScriptHandler();
            scripts.Concatenate("Events", new string[] { "mscorlib" });
            scripts.Run("Events");
            scripts.CreateInstance("Events");
            scripts.Invoke("_init_", events);

            Log.Message("Registering packets...", Log.DefaultFG);
            packets = new PacketHandler("login", new PacketProtocol().GetType(), events);

            Log.Level = conf.LogLevel;

            try
            {
                listener = new TcpListener(conf.ListenIp, conf.ListenPort);
                thread   = new Thread(Listen);
                thread.Start();
                // fixme
                syncServer = new SyncReceiver(conf.MasterIp.ToString(), conf.MasterPort, events);

                Log.Notice("Debugging mode: {0}", conf.Debug ? "on" : "off");
                Log.Notice("Whitelist: {0}", conf.WhiteList ? "on" : "off");
                Log.Notice("Minerva started in: {0} seconds", (Environment.TickCount - start) / 1000.0f);
            }
            catch (Exception e)
            {
                Log.FatalError(e.Message);
                #if DEBUG
                throw e;
                #endif
            }
        }
コード例 #30
0
ファイル: Server.cs プロジェクト: lKnuckles/minerva
        public Server(int server, int channel)
        {
            this.server  = server;
            this.channel = channel;

            Console.Title         = "Minerva Channel Server";
            Console.CursorVisible = false;

            int start = Environment.TickCount;

            Util.Info.PrintLogo();
            Console.WriteLine();

            AppDomain.CurrentDomain.UnhandledException += UnhandledException;


            Log.Start(string.Format("Channel_{0}_{1}", server, channel));    // Start logging service

            clients = new Dictionary <ulong, ClientHandler>();
            events  = new EventHandler();
            events.OnClientDisconnect += (sender, client) => { Log.Notice("Client {0} disconnected from Channel Server", client.RemoteEndPoint); clients.Remove((ulong)client.Metadata["magic"]); };
            events.OnError            += (sender, message) => { Log.Error(message); };
            events.OnReceivePacket    += (sender, e) => { Log.Received(e.Name, e.Opcode, e.Length); };
            events.OnSendPacket       += (sender, e) => { Log.Sent(e.Name, e.Opcode, e.Length); };
            events.OnWarp             += (sender, client, map, x, y) => { client.Metadata["map"] = maps[map]; maps[map].MoveClient(client, x / 16, y / 16); maps[map].UpdateCells(client); };

            /*Console.WriteLine("Compiling and registering scripts...");
             * scripts = new ScriptHandler();
             * scripts.Concatenate("Events", new string[] { "mscorlib" });
             * scripts.Run("Events");
             * scripts.CreateInstance("Events");
             * dynamic result = scripts.Invoke("_init_", events);*/

            try
            {
                Log.Message("Reading configuration...", Log.DefaultFG);
                //Configuration.Load(String.Format("Channel_{0}_{1}", server, channel)); Ported to Global.Global.Config)
                Global.Config.LoadChannel(server, channel);

                mapLoader = new MapLoader();
                maps      = mapLoader.LoadMaps();

                Log.Message("Registering packets...", Log.DefaultFG);
                packets = new PacketHandler("world", new PacketProtocol().GetType(), events);

                //listener = new TcpListener(System.Net.IPAddress.Any, Configuration.Port); Ported to Global.Global.Config
                listener = new TcpListener(System.Net.IPAddress.Any, Global.Config.getChannelPort(server, channel));
                thread   = new Thread(Listen);
                thread.Start();

                //syncServer = new SyncReceiver(Configuration.MasterIP, Configuration.MasterPort); Ported to Global.Global.Config
                syncServer = new SyncReceiver(Global.Config.MasterIP.ToString(), Global.Config.MasterPort);
                syncServer.OnSyncSuccess += (sender, e) =>
                {
                    //var aa = Configuration.IP.GetAddressBytes(); Ported to Global.Global.Config
                    var aa      = Global.Config.IP.GetAddressBytes();
                    var address = BitConverter.ToUInt32(aa, 0);
                    //Authentication.RegisterChannel(syncServer, server, channel, 0, address, Configuration.Port, 100); Ported to Global.Global.Config
                    Authentication.RegisterChannel(syncServer, server, channel, 0, address, Global.Config.getChannelPort(server, channel), 100);
                };

                Log.Notice("Minerva started in: {0} seconds", (Environment.TickCount - start) / 1000.0f);
            }
            catch (Exception e)
            {
                Log.Error(e.Message);
                #if DEBUG
                throw e;
                #endif
            }
        }