private void CharFile_1(string AccountName, string CharName) { TCharInfo CharInfo = D2DBS.charfile.GetCharInfo(AccountName, CharName); ushort Status = (ushort)CharInfo.summary.charstatus; int expansion = D2DBS.charfile.GetExpansion(Status); int hardcore = D2DBS.charfile.GetHardcore(Status); int Ladder = D2DBS.charfile.GetLadder(Status); D2DBS.log.Write("debug", "Charinfo for `" + CharName + "`(*" + AccountName + "): name " + CharInfo.header.charname + " acc " + CharInfo.header.account + " level " + CharInfo.portrait.level.ToString() + " class " + CharInfo.portrait.char_class.ToString() + " explow " + CharInfo.summary.experience + " exp " + expansion.ToString() + ", hc " + hardcore.ToString() + ", lad " + Ladder.ToString()); }
public bool SetCharInfo(string AccountName, string CharName, TCharInfo CharInfo) { try { CharInfo.header.last_time = (int)((DateTime.Now - TimeStampStart).TotalSeconds); return(SetCharInfoRaw(AccountName, CharName, D2DBS.core.StructToBytes(CharInfo))); } catch { return(false); } }
private int HandleSaveCharInfo(ConnInfo Conn, List <byte> buf) { TGSSaveCharInfoRequest packet = new TGSSaveCharInfoRequest(); int pos = Marshal.SizeOf(packet); packet = (TGSSaveCharInfoRequest)D2DBS.core.BytesToStruct(buf.ToArray(), Marshal.SizeOf(packet), packet.GetType()); string[] Names = BytesToString(buf.GetRange(pos, buf.Count - pos - packet.datalen - 1)).Split('\0'); string AccountName = Names[0]; string CharName = Names[1]; string CharVersion = D2DBS.config["char_version"]; byte[] data = buf.GetRange(buf.Count - packet.datalen, packet.datalen).ToArray(); TCharInfo CharInfo = (TCharInfo)D2DBS.core.BytesToStruct(data, typeof(TCharInfo)); TDBSSaveDataReply rpacket = new TDBSSaveDataReply(); byte[] rawcharname = StringToChars(CharName); rpacket.h.seqno = packet.h.seqno; rpacket.h.type = (byte)EPacketType.DBSSaveDataReply; rpacket.h.size = (short)(Marshal.SizeOf(rpacket) + rawcharname.Length); rpacket.datatype = 2; if (D2DBS.charfile.SetCharInfo(AccountName, CharName, CharInfo) == true) { D2DBS.mysql.Execute("INSERT DELAYED INTO `charstat` (`version`, `charname`, `accname`, `charclass`, `level`, `ist`, `lastupdate`) SELECT '" + CharVersion + "', '" + CharName + "', '" + AccountName + "', '" + CharInfo.summary.charclass.ToString() + "', '" + CharInfo.summary.charlevel.ToString() + "', '0', UNIX_TIMESTAMP() FROM `charstat` WHERE NOT EXISTS (SELECT `charname` FROM `charstat` WHERE `version` = '" + CharVersion + "' `charname` = '" + CharName + "') LIMIT 1"); D2DBS.mysql.Execute("UPDATE LOW_PRIORITY `charstat` SET `accname` = '" + AccountName + "', `charclass` = '" + CharInfo.summary.charclass.ToString() + "', `level` = '" + CharInfo.summary.charlevel.ToString() + "', `lastupdate` = UNIX_TIMESTAMP() WHERE version = '" + CharVersion + "' AND charname = '" + CharName + "'"); rpacket.result = 0; D2DBS.log.Write("info", "Saved charinfo `" + CharName + "`(*" + AccountName + ") for gs " + Conn.GSId.ToString()); } else { rpacket.result = 1; D2DBS.log.Write("info", "Failed to saved charinfo `" + CharName + "`(*" + AccountName + ") for gs " + Conn.GSId.ToString()); } lock (Conn.StreamLocker) { Conn.NetWriter.Write(D2DBS.core.StructToBytes(rpacket)); Conn.NetWriter.Write(rawcharname); Conn.NetWriter.Flush(); } return(0); }
private int HandleGetDataRequest(ConnInfo Conn, List <byte> buf) { TGSGetDataRequest packet = new TGSGetDataRequest(); int pos = Marshal.SizeOf(packet); packet = (TGSGetDataRequest)D2DBS.core.BytesToStruct(buf.ToArray(), Marshal.SizeOf(packet), packet.GetType()); string[] Names = BytesToString(buf.GetRange(pos, buf.Count - pos)).Split('\0'); string AccountName = Names[0]; string CharName = Names[1]; TCharInfo CharInfo = new TCharInfo(); byte result = 1; byte[] data = null; if (packet.datatype == 1) { if (D2DBS.charlock.SetCharLock(CharName, Conn.GSId)) { data = D2DBS.charfile.GetCharSave(AccountName, CharName); if (data == null) { result = 1; D2DBS.log.Write("error", "Failed to load charsave `" + CharName + "`(*" + AccountName + ") for gs " + Conn.GSId.ToString()); D2DBS.charlock.UnlockChar(CharName); } else { result = 0; D2DBS.log.Write("info", "Loaded charsave `" + CharName + "`(*" + AccountName + ") for gs " + Conn.GSId.ToString()); } } else { int LockGSId = D2DBS.charlock.GetGSIdByLock(CharName); result = 1; D2DBS.log.Write("warn", "Char `" + CharName + "`(*" + AccountName + ") already locked on gs " + LockGSId.ToString() + " for gs " + Conn.GSId.ToString()); //KickPlayer(D2DBS.net.GetConnByGSId(LockGSId), CharName); } } else { data = D2DBS.charfile.GetCharInfoRaw(AccountName, CharName); D2DBS.log.Write("info", "Loaded charinfo `" + CharName + "`(*" + AccountName + ") for gs " + Conn.GSId.ToString()); } if (result == 0) { byte[] RAWCharInfo = D2DBS.charfile.GetCharInfoRaw(AccountName, CharName); if (RAWCharInfo == null) { D2DBS.log.Write("error", "Failed to load charinfo `" + CharName + "`(*" + AccountName + ") for gs " + Conn.GSId.ToString()); D2DBS.charlock.UnlockChar(CharName); result = 1; } else { CharInfo = (TCharInfo)D2DBS.core.BytesToStruct(RAWCharInfo, typeof(TCharInfo)); } } TDBSGetDataReply rpacket = new TDBSGetDataReply(); if (result == 0) { int ladder_time = int.Parse(D2DBS.config["ladderinit_time"]); if (D2DBS.charfile.GetLadder((ushort)CharInfo.summary.charstatus) == 1) { if (CharInfo.header.create_time < ladder_time) { rpacket.allowladder = 0; D2DBS.log.Write("info", "Char `" + CharName + "`(*" + AccountName + ") expired for ladder, converting to non-ladder"); } else { rpacket.allowladder = 1; } } else { rpacket.allowladder = 0; } rpacket.charcreatetime = CharInfo.header.create_time; rpacket.datalen = (short)data.Length; } else { rpacket.allowladder = 0; rpacket.charcreatetime = 0; rpacket.datalen = 0; } byte[] rawcharname = StringToChars(CharName); rpacket.h.seqno = packet.h.seqno; rpacket.h.type = (byte)EPacketType.DBSGetDataReply; rpacket.h.size = (short)(Marshal.SizeOf(rpacket) + rawcharname.Length + rpacket.datalen); rpacket.datatype = packet.datatype; rpacket.result = result; lock (Conn.StreamLocker) { Conn.NetWriter.Write(D2DBS.core.StructToBytes(rpacket)); Conn.NetWriter.Write(rawcharname); if (rpacket.datalen > 0) { Conn.NetWriter.Write(data); } Conn.NetWriter.Flush(); } return(0); }
public bool SetCharInfo(string AccountName, string CharName, TCharInfo CharInfo) { try { CharInfo.header.last_time = (int)((DateTime.Now - TimeStampStart).TotalSeconds); return SetCharInfoRaw(AccountName, CharName, D2DBS.core.StructToBytes(CharInfo)); } catch { return false; } }