public static HeroBasicInfo[] getBasicInfos(List <int> heroIDs) { var lst = new List <HeroBasicInfo>(); if (heroIDs.Count == 0) { return(lst.ToArray()); } var res = DB2.GetInstance().Select( "heroID, playerName, basicInfo", "Hero", $"heroID IN ({string.Join(",", heroIDs)})" ); HeroBasicInfo tmp; if (res != null) { foreach (var row in res) { tmp = HeroBasicInfo.fromJson(row[2]); tmp.heroID = int.Parse(row[0]); tmp.heroName = row[1]; lst.Add(tmp); } } return(lst.ToArray()); }
public void loadItemsFromDB() { Console.WriteLine("[!] Bag: " + string.Join(",", items)); // TODO: load items from db if (items.Count == 0) { return; } var res = DB2.GetInstance().Select( "itemUID, itemInfo", "UniqueItem", $"itemUID IN ({string.Join(",", items)});" ); if (res == null) { return; } // load items to memory Item item; foreach (var db_item in res) { item = Item.fromJson(db_item[1]); itemDict.Add(uint.Parse(db_item[0]), item); itemPos.Add(item.position, item.itemUID); } }
public bool addItem(Hero p, Item item) { // TODO: pick up auto stack // TODO: send add-item to backpack packet byte pos; for (pos = 1; pos < size; pos++) { // looking for empty pos if (!itemPos.ContainsKey(pos)) { break; } } if (pos < size) { item.position = pos; this.items.Add(item.itemUID); this.itemPos.Add(pos, item.itemUID); this.itemDict.Add(item.itemUID, item); DB2.GetInstance().Insert( "UniqueItem", new Dictionary <string, object>() { { "itemUID", item.itemUID }, { "itemInfo", item.toJson() }, { "belongsTo", p.heroID }, } ); return(true); } else { // backpack is full. // TODO: send cannot pick up packet return(false); } }
public static Hero getHero(string username, byte position) { var res = DB2.GetInstance().Select( $"h.heroID as h_heroID, l.hero{position} as l_heroID, h.fullInfo as fullInfo, h.playerName as playerName", "Login l, Hero h", $"l.hero{position} = h.heroID AND username = @uname LIMIT 1", new Dictionary <string, object>() { { "uname", username } } ); if (res.Count != 1) { return(null); } var tmp = Hero.fromJson(res[0][2]); tmp.heroID = int.Parse(res[0][0]); tmp.heroName = res[0][3]; return(tmp); }
static void Main(string[] args) { Version version = Assembly.GetExecutingAssembly().GetName().Version; AssemblyDescriptionAttribute releaseDate = (AssemblyDescriptionAttribute)Attribute.GetCustomAttribute(Assembly.GetExecutingAssembly(), typeof(AssemblyDescriptionAttribute)); Console.WriteLine($"============== FeatherServer ==============\r\n + Build: {version} [{releaseDate.Description}]\r\n\r\n"); Console.WriteLine("Note: Type \"exit\" to exit.\r\n"); // set encoder System.Text.Encoding.RegisterProvider(System.Text.CodePagesEncodingProvider.Instance); Lib.textEncoder = Encoding.GetEncoding("GBK"); Console.WriteLine($"[!] Preparing Database Connection..."); Lib.lastUID = DB2.GetInstance().getLastInsertedID("Hero", "heroID"); Lib.lastItemUID = (uint)DB2.GetInstance().getLastInsertedID("UniqueItem", "ItemUID"); Console.WriteLine($"[*] Last Usable HeroID : [{Lib.lastUID++}]"); Console.WriteLine($"[*] Last Usable ItemUID: [{Lib.lastItemUID++}]"); Console.WriteLine("[!] Registering Listener ..."); Thread t = new Thread(delegate() { Server srv = new Server("0.0.0.0", 6011); }); t.Start(); Console.WriteLine("[+] Everythings Ready!"); do { Console.Write("# > "); consoleCmdHandler.handle(Console.ReadLine()); } while (!Lib.endSrv); }