예제 #1
0
 public void StartSync(string ip, int port)
 {
     p          = this;
     this.ip    = ip;
     this.port  = port;
     syncThread = new Thread(Listen);
     syncThread.Start();
 }
예제 #2
0
 void ReceiveThread()
 {
     while (true)
     {
         AwesomeSockets.Buffer.ClearBuffer(recvBuffer);
         try
         {
             AweSock.ReceiveMessage(socket, recvBuffer);
             PipeServer.ProcessPacket(this, recvBuffer);
         }
         catch (Exception)
         {
             rThread.Abort();
         }
     }
 }
예제 #3
0
        public Server()
        {
            Console.Title         = "Minerva Master Server";
            Console.CursorVisible = false;

            int start = Environment.TickCount;

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

            AppDomain.CurrentDomain.UnhandledException += UnhandledException;

            Configuration.Load();
            Log.Start("Master", Configuration.masterLog, Configuration.masterLogLvl);

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

                Log.Message("Loading initial char data...", Log.DefaultFG);
                var xml   = XDocument.Load("data/InitialData.xml");
                var node  = xml.Root.Element("char_init");
                var stats = new Dictionary <int, List <int> >();

                foreach (var n in node.Elements("init"))
                {
                    stats.Add(int.Parse(n.Attribute("style").Value),
                              new List <int>()
                    {
                        int.Parse(n.Attribute("world_id").Value),
                        int.Parse(n.Attribute("x").Value),
                        int.Parse(n.Attribute("y").Value),
                        int.Parse(n.Attribute("suit_1").Value),
                        int.Parse(n.Attribute("glove_2").Value),
                        int.Parse(n.Attribute("boot_3").Value),
                        int.Parse(n.Attribute("rhand_4").Value),
                        (n.Attribute("lhand_5").Value != "") ? int.Parse(n.Attribute("lhand_5").Value) : -1,
                        int.Parse(n.Attribute("hp").Value),
                        int.Parse(n.Attribute("mp").Value)
                    }
                              );
                }

                node = xml.Root.Element("initstat");

                foreach (var n in node.Elements("initstat"))
                {
                    stats[int.Parse(n.Attribute("id").Value)].AddRange(
                        new[]
                    {
                        int.Parse(n.Attribute("str").Value),
                        int.Parse(n.Attribute("int").Value),
                        int.Parse(n.Attribute("dex").Value)
                    }
                        );
                }

                xml  = XDocument.Load("data/new_char.xml");
                node = xml.Root.Element("init");
                var items      = new Dictionary <int, List <Tuple <byte[], ushort, byte> > >();
                var skills     = new Dictionary <int, List <int[]> >();
                var quickslots = new Dictionary <int, List <int[]> >();

                foreach (var n in node.Elements("item"))
                {
                    var _class = int.Parse(n.Attribute("class").Value);
                    var item   = new Item();
                    var amount = 0;
                    var slot   = byte.Parse(n.Attribute("slot").Value);

                    item.ID = ushort.Parse(n.Attribute("id").Value);
                    var a = n.Attribute("bonus");
                    if (a != null)
                    {
                        item.Bonus = byte.Parse(a.Value);
                    }
                    a = n.Attribute("is_bound");
                    if (a != null)
                    {
                        item.IsBound = byte.Parse(a.Value);
                    }
                    a = n.Attribute("craft_type");
                    if (a != null)
                    {
                        item.CraftType = byte.Parse(a.Value);
                    }
                    a = n.Attribute("craft_bonus");
                    if (a != null)
                    {
                        item.CraftBonus = byte.Parse(a.Value);
                    }
                    a = n.Attribute("upgrades");
                    if (a != null)
                    {
                        item.Upgrades = byte.Parse(a.Value);
                    }
                    a = n.Attribute("upgrade_1");
                    if (a != null)
                    {
                        item.Upgrade1 = byte.Parse(a.Value);
                    }
                    a = n.Attribute("upgrade_2");
                    if (a != null)
                    {
                        item.Upgrade2 = byte.Parse(a.Value);
                    }
                    a = n.Attribute("upgrade_3");
                    if (a != null)
                    {
                        item.Upgrade3 = byte.Parse(a.Value);
                    }
                    a = n.Attribute("upgrade_4");
                    if (a != null)
                    {
                        item.Upgrade4 = byte.Parse(a.Value);
                    }
                    a = n.Attribute("expiration");
                    if (a != null)
                    {
                        item.ExpirationDate = uint.Parse(a.Value);
                    }
                    a = n.Attribute("amount");
                    if (a != null)
                    {
                        amount = int.Parse(a.Value);
                    }

                    if (!items.ContainsKey(_class))
                    {
                        items[_class] = new List <Tuple <byte[], ushort, byte> >();
                    }

                    items[_class].Add(Tuple.Create(item.ToByteArray(), (ushort)amount, slot));
                }

                foreach (var n in node.Elements("skill"))
                {
                    var _class = int.Parse(n.Attribute("class").Value);
                    var skill  = new int[3];

                    skill[0] = int.Parse(n.Attribute("id").Value);
                    skill[1] = int.Parse(n.Attribute("level").Value);
                    skill[2] = int.Parse(n.Attribute("slot").Value);

                    if (!skills.ContainsKey(_class))
                    {
                        skills[_class] = new List <int[]>();
                    }

                    skills[_class].Add(skill);
                }

                foreach (var n in node.Elements("quickslot"))
                {
                    var _class    = int.Parse(n.Attribute("class").Value);
                    var quickslot = new int[2];

                    quickslot[0] = int.Parse(n.Attribute("id").Value);
                    quickslot[1] = int.Parse(n.Attribute("slot").Value);

                    if (!quickslots.ContainsKey(_class))
                    {
                        quickslots[_class] = new List <int[]>();
                    }

                    quickslots[_class].Add(quickslot);
                }

                Log.Message("Starting Pipe Server...", Log.DefaultFG);
                var pipe = new PipeServer(stats, items, skills, quickslots);
                pipe.RunPipe();

                Log.Notice("Minerva started in: {0} seconds", (Environment.TickCount - start) / 1000.0f);
            }
            catch (Exception e)
            {
                Log.Error(e.Message, "[Master::Server::" + e.TargetSite.Name + "()]");
                #if DEBUG
                throw e;
                #endif
            }
        }
예제 #4
0
        public static void ProcessPacket(IPCReceiver receiver, AwesomeSockets.Buffer buffer)
        {
            var        reader = new IPCReader(buffer);
            var        packet = reader.ReadOpcode();
            PipeServer p      = PipeServer.Instance;

            if (packet == null)
            {
                return;
            }

            switch ((IPC)packet)
            {
            case IPC.FetchAccount: p.FetchAccount(receiver, reader); break;

            case IPC.UpdateIPDate: p.UpdateIPDate(receiver, reader); break;

            case IPC.AddUser: p.AddUser(receiver, reader); break;

            case IPC.GetUser: p.GetUser(receiver, reader); break;

            case IPC.ChannelList: p.GetChannels(receiver, reader); break;

            case IPC.RegisterChannel: p.AddChannel(receiver, reader); break;

            case IPC.GetCharacterList: p.GetCharacters(receiver, reader); break;

            case IPC.CreateCharacter: p.CreateCharacter(receiver, reader); break;

            case IPC.DeleteCharacter: p.DeleteCharacter(receiver, reader); break;

            case IPC.VerifyPassword: p.VerifyPassword(receiver, reader); break;

            case IPC.UpdatePosition: p.UpdateCharacterPosition(receiver, reader); break;

            case IPC.GetFullCharacter: p.GetFullCharacter(receiver, reader); break;

            case IPC.GetSlotOrder: p.GetSlotOrder(receiver, reader); break;

            case IPC.SetSlotOrder: p.SetSlotOrder(receiver, reader); break;

            case IPC.SetQuickSlots: p.SetQuickSlots(receiver, reader); break;

            case IPC.UpdateStatPoints: p.UpdateStatPoints(receiver, reader); break;

            case IPC.UpdateSkillPoints: p.UpdateSkillPoints(receiver, reader); break;

            case IPC.GetSubPass: p.GetSubPass(receiver, reader); break;

            case IPC.SetSubPass: p.SetSubPass(receiver, reader); break;

            case IPC.GetSubPassQuestion: p.GetSubPassQuestion(receiver, reader); break;

            case IPC.CheckSubPassAnswer: p.CheckSubPassAnswer(receiver, reader); break;

            case IPC.CheckSubPass: p.CheckSubPass(receiver, reader); break;

            case IPC.RemoveSubPass: p.RemoveSubPass(receiver, reader); break;

            case IPC.GetSubPassTime: p.GetSubPassTime(receiver, reader); break;

            case IPC.SetSubPassTime: p.SetSubPassTime(receiver, reader); break;
            }
        }