public int _new_user() { UserClient _new_client = new UserClient("Client_" + AllUser_database.Count.ToString(), "Cookies" + AllUser_database.Count, AllUser_database.Count); XElement user = new XElement("user"); XAttribute attrib = new XAttribute("_ID_USER", (this.AllUser_database.Count + 1)); XElement login = new XElement("_Login", "Client_" + (this.AllUser_database.Count + 1)); XElement cookies = new XElement("_cookies", "Cookies" + (this.AllUser_database.Count + 1)); user.Add(attrib); user.Add(login); user.Add(cookies); XElement _list_Prey = new XElement("_list_Prey"); XElement _Prey = new XElement("_Prey"); XElement _IP_Last = new XElement("IP_Last", 0); XElement _Port = new XElement("Port", 0); XElement _Name_Prey = new XElement("Name_Prey", 0); XElement _Token_Prey = new XElement("Token_Prey", 0); _Prey.Add(_IP_Last); _Prey.Add(_Port); _Prey.Add(_Name_Prey); _Prey.Add(_Token_Prey); _list_Prey.Add(_Prey); user.Add(_list_Prey); XDocument ff = new XDocument(); xdoc.Element("users").Add(user); xdoc.Save("userdatabase.xml"); AllUser_database.Add(_new_client); return(this.AllUser_database.Count); }
private static void _AppendPrey(string[] str_com, IPEndPoint remoteEP, AllUser AllPlayer) { UserClient _one_user = new UserClient(str_com[4], str_com[5], Convert.ToInt32(str_com[3])); Prey _one_prey = new Prey(str_com[1], str_com[2]); bool notfound = false; foreach (var _user in AllPlayer.AllUser_database) { if (_CompareUser(_user, _one_user)) { foreach (var _prey in AllPrey.AllPrey_database) { if (_ComparePrey(_prey, _one_prey)) { _user._all_sacrifice.Add(_prey); Console.WriteLine("[append_prey][OK]"); byte[] msg = BaseTools.Convertbtst("[append_prey][OK]"); ReceiverUDP.udpServer.Send(msg, msg.Length, remoteEP); AllPlayer._SavePrey(_prey, _user); notfound = true; break; } } break; } } if (!notfound) { byte[] btnotfound = BaseTools.Convertbtst("[append_prey][not found]"); ReceiverUDP.udpServer.Send(btnotfound, btnotfound.Length, remoteEP); } }
private static bool _CompareUser(UserClient _baseuser, UserClient _client) { if (_baseuser._Login == _client._Login && _baseuser._cookies == _client._cookies && _baseuser._ID_USER == _client._ID_USER) { return(true); } else { return(false); } }
public static void _OtherCommand(AllUser AllPlayer, IPEndPoint remoteEP, string[] mas) { UserClient _client = new UserClient(mas[2], mas[1], Convert.ToInt32(mas[0])); switch (mas[3]) { case "get_all_sacrifice": _SearchUserInBase(AllPlayer, remoteEP, ref _client); break; default: Console.WriteLine(string.Join("", mas)); break; } }
public static void _SearchUserInBase(AllUser AllPlayer, IPEndPoint remoteEP, ref UserClient _client) { foreach (var _user in AllPlayer.AllUser_database) { if (_CompareUser(_user, _client)) { _user._now_ip_port = remoteEP; _client._now_ip_port = remoteEP; _client._all_sacrifice = _user._all_sacrifice; _client.online = true; string allSacrifice = "[get_all_sacrifice]" + _client._AllSacrificeToString(); byte[] com = BaseTools.Convertbtst(allSacrifice); ReceiverUDP.udpServer.Send(com, com.Length, remoteEP); } } }
public AllUser() { AllUser_database = new List <UserClient>(); this.xdoc = XDocument.Load("userdatabase.xml"); foreach (XElement userElement in xdoc.Element("users").Elements("user")) { XAttribute idAttribute = userElement.Attribute("_ID_USER"); XElement _cookiesElement = userElement.Element("_cookies"); XElement LoginElement = userElement.Element("_Login"); XElement preyElement = userElement.Element("_list_Prey"); List <Prey> _all_sacrifice = _Get_Prey(preyElement); UserClient _new_client = new UserClient(LoginElement.Value, _cookiesElement.Value, Convert.ToInt32(idAttribute.Value), _all_sacrifice); AllUser_database.Add(_new_client); } }
public void _SavePrey(Prey _one_prey, UserClient _user) { var result = xdoc.Element("users").Elements("user").Single(x => x.Attribute("_ID_USER").Value == _user._ID_USER.ToString()); XElement _Prey = new XElement("_Prey"); XElement _IP_Last = new XElement("IP_Last", _one_prey.ip.Address); XElement _Port = new XElement("Port", _one_prey.ip.Port); XElement _Name_Prey = new XElement("Name_Prey", _one_prey.Name_sacrifice); XElement _Token_Prey = new XElement("Token_Prey", _one_prey.Token_sacrifice); _Prey.Add(_IP_Last); _Prey.Add(_Port); _Prey.Add(_Name_Prey); _Prey.Add(_Token_Prey); result.Element("_list_Prey").Add(_Prey); XDocument ff = new XDocument(); //xdoc.Element("users").Add(user); xdoc.Save("userdatabase.xml"); }