public void AddFriend(SFriend friend) { krnGateway.AddFriend(friend.ID, friend.Port, friend.ServerIP, friend.UserHash, 0, friend.OurName, friend.Name, friend.Software, friend.Version, friend.FriendSlot); InterfaceClient source = new InterfaceClient(); source.Name=friend.OurName; source.ID=friend.ID; source.Port=friend.Port; if (friend.UserHash!=null) source.UserHash=friend.UserHash; OnAddingFriend(source); }
public void Add(uint ID, ushort Port,uint ServerIP, byte[] ClientHash, ushort ServerPort, string OurName, string Name, string Software, uint Version) { int index = m_FindFriend(ID,ClientHash,Port); Constants.FriendLevel friendLevel; if (index>=0) { SFriend Friend = (SFriend)List[index]; if (OurName!="") Friend.OurName = OurName; Friend.Name = Name; Friend.ID = ID; Friend.Port = Port; if (ServerIP!=0) Friend.ServerIP = ServerIP; if (ServerPort!=0) Friend.ServerPort = ServerPort; Friend.LastOnline = DateTime.Now; if (Software!=null) Friend.Software = Software; if (Version!=0) Friend.Version = Version; if (ClientHash!=null) Friend.UserHash = ClientHash; List[index] = Friend; // Friend.FriendSlot=friendSlot; // CClient client=CKernel.ClientsList.GetClient(Friend.ID,Friend.Port,Friend.ServerIP,Friend.UserHash); // if (client!=null) // { // if (Friend.FriendSlot) // friendLevel=Constants.FriendLevel.FriendSlot; // else // friendLevel=Constants.FriendLevel.Friend; // client.FriendStatus=friendLevel; // } } else { SFriend Friend = new SFriend(); Friend.OurName = OurName; Friend.Name = Name; Friend.UserHash = ClientHash; Friend.ID = ID; Friend.Port = Port; Friend.ServerPort = ServerPort; Friend.ServerIP = ServerIP; Friend.LastOnline = DateTime.Now; Friend.Software = Software; Friend.Version = Version; Friend.FriendSlot = false; List.Add(Friend); friendLevel=Constants.FriendLevel.Friend; CKernel.ClientsList.AddClient(Friend.ID,Friend.Port,0,Friend.UserHash,Friend.Port,null,friendLevel); } this.Save(); }
private void buttonAddFriendOk_Click(object sender, System.EventArgs e) { bool validate = false; uint ip; ip = 0; if ((textBoxIP.Text != "") && (textBoxName.Text != "") && (textBoxPort.Text != "")) { //validate ip or id //if (Regex.IsMatch(textBoxIP.Text, @"^(((?<=255\\d{1,3})\.){3}(?<=255\\d{1,3}))$")) if (Regex.IsMatch(textBoxIP.Text, @"^(((\d{1,3})\.){3}(\d{1,3}))$")) { try { IPAddress DirectionIP = IPAddress.Parse(textBoxIP.Text); ip = BitConverter.ToUInt32(DirectionIP.GetAddressBytes(), 0); } catch { ip = 0; } } if ((ip == 0) && (Regex.IsMatch(textBoxIP.Text, @"^\d{9,12}$"))) { ip = Convert.ToUInt32(textBoxIP.Text); } //validate port if ((ip != 0) && (Regex.IsMatch(textBoxPort.Text, @"^\d{1,5}$")) && Convert.ToInt32(textBoxPort.Text) <= 65535) { validate = true; } if ((!textBoxIP.Enabled) && (!textBoxPort.Enabled)) validate = true; } if (validate) { SFriend friend = new SFriend(); friend.Name = textBoxName.Text; friend.OurName = textBoxName.Text; if (textBoxUserHash.Text != "") { byte[] x = new byte[textBoxUserHash.Text.Length]; x = Convert.FromBase64String(textBoxUserHash.Text); friend.UserHash = x; } friend.ID = ip; friend.FriendSlot = false; friend.Port = Convert.ToUInt16(textBoxPort.Text); panelAddFriend.Visible = false; krnGateway.AddFriend(friend); buttonAddFriend.Visible = true; } else { //send a message box } }
private bool SetValueFromXmlElement(XmlElement element) { try { XmlNodeList nodes = element.ChildNodes; foreach (XmlElement el in nodes) { if ( el.Name == "Friend" ) { SFriend my_Friend = new SFriend(); my_Friend.FriendSlot=false; //load Friend.UserHash if (el.Attributes["UserHash"].InnerText!="") { byte[] x = null; switch (_currentversion) { case "0.1": x = new byte[el.Attributes["UserHash"].InnerText.Length]; x = Encoding.Default.GetBytes( el.Attributes["UserHash"].InnerText ); break; case "0.2": x = Convert.FromBase64String( el.Attributes["UserHash"].InnerText ); break; } my_Friend.UserHash = (byte[])x; } else { my_Friend.UserHash = null; } //load Friend.ID my_Friend.ID = uint.Parse(el.Attributes["ID"].InnerText); //load Friend.OurName my_Friend.OurName = el.Attributes["OurName"].InnerText; //load Friend.Name my_Friend.Name = el.Attributes["Name"].InnerText; //load Friend.Port my_Friend.Port = ushort.Parse(el.Attributes["Port"].InnerText); //load Friend.Software my_Friend.Software = el.Attributes["Software"].InnerText; //load Friend.Version my_Friend.Version = uint.Parse(el.Attributes["Version"].InnerText); //load Friend.LastOnline my_Friend.LastOnline = new DateTime(long.Parse(el.Attributes["LastOnline"].InnerText)); //load friendSlot if (el.Attributes["FriendSlot"]!=null) { my_Friend.FriendSlot=bool.Parse(el.Attributes["FriendSlot"].InnerText); } List.Add(my_Friend); Constants.FriendLevel friendSlot; if (my_Friend.FriendSlot) friendSlot=Constants.FriendLevel.FriendSlot; else friendSlot=Constants.FriendLevel.Friend; CKernel.ClientsList.AddClient(my_Friend.ID,my_Friend.Port,0,my_Friend.UserHash,my_Friend.Port,null,friendSlot); //switch ( el.Attributes["type"].InnerText ) } } } catch { CLog.Log(Constants.Log.Info,"Error loading friends list"); return false; } return true; }