/// <summary> /// Removes a connected user from the group. /// The user reconnects at the next session. /// </summary> /// <param name="pUsername">Client</param> public void Disconnect(NetComUser pUser) { if (OnlineMembers.Contains(pUser)) { OnlineMembers.Remove(pUser); } }
public RichMessageBox(NetComUser pSender, NetComUser pReceiver, string pMessage, string pCaption, System.Windows.Forms.MessageBoxButtons pButtons, System.Windows.Forms.MessageBoxIcon pIcon) : base(pSender, pReceiver, pMessage, null) { object[] prm = new object[3]; prm[0] = pCaption; switch (pButtons) { case System.Windows.Forms.MessageBoxButtons.AbortRetryIgnore: prm[1] = "MB1"; break; case System.Windows.Forms.MessageBoxButtons.OK: prm[1] = "MB2"; break; case System.Windows.Forms.MessageBoxButtons.OKCancel: prm[1] = "MB3"; break; case System.Windows.Forms.MessageBoxButtons.RetryCancel: prm[1] = "MB4"; break; case System.Windows.Forms.MessageBoxButtons.YesNo: prm[1] = "MB5"; break; case System.Windows.Forms.MessageBoxButtons.YesNoCancel: prm[1] = "MB6"; break; } switch (pIcon) { case System.Windows.Forms.MessageBoxIcon.Information: prm[2] = "MI1"; break; case System.Windows.Forms.MessageBoxIcon.Error: prm[2] = "MI2"; break; case System.Windows.Forms.MessageBoxIcon.Exclamation: prm[2] = "MI3"; break; case System.Windows.Forms.MessageBoxIcon.None: prm[2] = "MI4"; break; case System.Windows.Forms.MessageBoxIcon.Question: prm[2] = "MI5"; break; } parameters = prm; }
/// <summary> /// Sets the public-key of the receiver. /// </summary> /// <param name="pPublicKey">Public-key of the receiver</param> public void SetReceiverPublicKey(string pPublicKey) { if (Receiver == null) { Receiver = new NetComUser(); } Receiver.SetUserData("", "", pPublicKey); }
/// <summary> /// Provides a base for new custom instructions, or /// operates as a common interface for instructions /// </summary> /// <param name="pSender">Sender (local user) of the instruction</param> /// <param name="pReceiver">Receiver (remote user) of the instruction</param> /// <param name="pValue">Value of the instruction. Can be used as required.</param> /// <param name="pParameters">Parameters of the instruction. Can be used as required</param> public InstructionBase(NetComUser pSender, NetComUser pReceiver, string pValue = null, params object[] pParameters) { Receiver = pReceiver; Sender = pSender; value = pValue; parameters = pParameters; instruction = this.GetType().AssemblyQualifiedName; sInstruction = this.GetType().Name; ID = Guid.NewGuid().ToString(); }
// ╔════╤════════════════════════════════════════════════════════╗ // ║ 4d │ M E T H O D S ( P U B L I C ) ║ // ╟────┴────────────────────────────────────────────────────────╢ // ║ N O N - S T A T I C & S T A T I C ║ // ╚═════════════════════════════════════════════════════════════╝ #region ═╣ M E T H O D S ( P U B L I C ) ╠═ /// <summary> /// Adds a already connected user to the group. /// The user reconnects at the next session. /// </summary> /// <param name="pUser">Client</param> public void AddUser(NetComUser pUser) { if (!OnlineMembers.Contains(pUser)) { OnlineMembers.Add(pUser); } if (!GroupMembers.Contains(pUser.Username.ToLower())) { GroupMembers.Add(pUser.Username.ToLower()); } }
/// <summary> /// Tries to add a user to any groups /// that that it is a member of. /// </summary> /// <param name="pUser"></param> public void TryGroupAdd(NetComUser pUser) { for (int i = 0; i < userGroups.Count; i++) { for (int j = 0; j < userGroups[i].GroupMembers.Count; j++) { if (pUser.Username.ToLower() == userGroups[i].GroupMembers[j].ToLower()) { userGroups[i].AddUser(pUser); } } } }
public NofityIcon(NetComUser pSender, NetComUser pReceiver, string pText, string pTitle, int pDisplayDuration, ToolTipIcon pIcon) : base(pSender, pReceiver, pText, null) { object[] prm = new object[3]; prm[0] = pTitle; prm[1] = pDisplayDuration; switch (pIcon) { case ToolTipIcon.Error: prm[2] = "NI1"; break; case ToolTipIcon.Info: prm[2] = "NI2"; break; case ToolTipIcon.None: prm[2] = "NI3"; break; case ToolTipIcon.Warning: prm[2] = "NI4"; break; } parameters = prm; }
public AuthenticationServer2Client(NetComUser pSender, NetComUser pReceiver) : base(pSender, pReceiver, null, null) { }
public Message(NetComUser pSender, string pReceiverUsername, string pMessage) : base(pSender, null, pReceiverUsername, new object[] { pMessage }) { }
public Message(NetComUser pSender, NetComUser pReceiver, string pValue, object[] pParameters) : base(pSender, pReceiver, pValue, pParameters) { }
public KeyExchangeClient2Server(NetComUser pSender, NetComUser pReceiver) : base(pSender, pReceiver, pSender.RSAKeys.PublicKey, new object[] { pSender.Username }) { }
public KeyExchangeClient2Server(NetComUser pSender, NetComUser pReceiver, string pValue, object[] pParameters) : base(pSender, pReceiver, pValue, pParameters) { }
public AuthenticationReminder(NetComUser pSender, NetComUser pReceiver) : base(pSender, pReceiver, null, null) { }
public ToConsole(NetComUser pSender, NetComUser pReceiver, string pValue) : base(pSender, pReceiver, pValue, null) { }
public ToOutputStream(NetComUser pSender, NetComUser pReceiver, string pMessage) : base(pSender, pReceiver, pMessage, null) { }
/// <summary> /// Parses an encoded instruction-string and returns /// all instruction-objects included in the string. /// </summary> /// <param name="pLocalUser">Local user</param> /// <param name="pReceptionSocket">Remote user, from which the instruction was received</param> /// <param name="pInstructionString">Encoded instruction-string. Can contain multiple instructions.</param> /// <param name="pServerClientList">Client-List for authentication (NetComServer only!)</param> /// <returns></returns> internal static IEnumerable <InstructionBase> Parse(NetComUser pLocalUser, Socket pReceptionSocket, string pInstructionString, ClientList pServerClientList = null) { // RSA:<Base64>;RSA:<Base64>; List <InstructionBase> retInstr = new List <InstructionBase>(); lock (pLocalUser) { foreach (string encodedInstruction in pInstructionString.Split('%')) { if (string.IsNullOrEmpty(encodedInstruction)) { continue; } string instructionID = null; string frameworkVersion = null; string instructionsetVersion = null; string username = null; string password = null; string instruction = null; string value = null; List <object> parameters = new List <object>(); string signaturePlain = null; string signatureRSA = null; string publicKey = null; NetComUser user = null; // RSA:<Base64> bool rsaEncoded = false; string encInstr = encodedInstruction; if (encInstr.StartsWith("R:")) { rsaEncoded = true; encInstr = encInstr.Remove(0, 2); } // <Base64> string decodedInstruction; try { //decodedInstruction = Base64Handler.Decode(encInstr); decodedInstruction = encInstr; } catch (Exception ex) { (pLocalUser as NetComOperator).Debug("Instruction-Parsing: Could not decode from Base64.", DebugType.Error); if ((pLocalUser as NetComOperator).ShowExceptions) { (pLocalUser as NetComOperator).Debug($"({ex.GetType().Name}) {ex.Message}", DebugType.Exception); } continue; } // INS:B64,VAL:B64,PAR:B64#B64|B64#B64|, foreach (string encodedInstrSegment in decodedInstruction.Split('$')) { if (string.IsNullOrEmpty(encodedInstrSegment)) { continue; } // INS:B64 / PAR:B64#B64|B64#B64| string[] encodedSegmentParts = encodedInstrSegment.Split(':'); switch (encodedSegmentParts[0]) { case "IID": instructionID = encodedSegmentParts[1]; break; case "FWV": frameworkVersion = encodedSegmentParts[1]; break; case "ISV": instructionsetVersion = encodedSegmentParts[1]; break; case "PUK": publicKey = encodedSegmentParts[1]; break; case "USR": username = Base64Handler.Decode(encodedSegmentParts[1], "ERROR"); break; case "PSW": if (rsaEncoded) { password = RSAHandler.Decrypt(pLocalUser.RSAKeys.PrivateKey, encodedSegmentParts[1]); } break; case "SGP": signaturePlain = encodedSegmentParts[1]; break; case "SGC": if (rsaEncoded) { signatureRSA = encodedSegmentParts[1]; } break; case "INS": instruction = encodedSegmentParts[1]; break; case "VAL": value = Base64Handler.Decode(encodedSegmentParts[1], "ERROR"); break; case "PAR": foreach (string paramGroup in encodedSegmentParts[1].Split('|')) { if (string.IsNullOrEmpty(paramGroup)) { continue; } string[] paramParts = paramGroup.Split('#'); string paramTypeStr = paramParts[0]; string paramValueStr = Base64Handler.Decode(paramParts[1], "ERROR"); Type paramType = Type.GetType(paramTypeStr); try { object convParam = null; TypeConverter converter = TypeDescriptor.GetConverter(paramType); if (converter != null) { convParam = converter.ConvertFromString(paramValueStr); } else { convParam = null; } parameters.Add(convParam); } catch (NotSupportedException ex) { (pLocalUser as NetComOperator).Debug("Broadcast-Error.", DebugType.Error); if ((pLocalUser as NetComOperator).ShowExceptions) { (pLocalUser as NetComOperator).Debug($"({ex.GetType().Name}) {ex.Message}", DebugType.Exception); } throw new NetComParsingException($"*** Could not parse the following parameter: Type: {paramTypeStr}, Value: {paramValueStr} ***"); } } break; } } // Check if the instruction has been processed before if (instruction != typeof(InstructionLibraryEssentials.ReceptionConfirmation).AssemblyQualifiedName) { if ((pLocalUser as NetComOperator).InstructionLogIncomming.Contains(instructionID)) { if (pLocalUser.GetType() == typeof(NetComClient)) { (pLocalUser as NetComClient).Send(new InstructionLibraryEssentials.ReceptionConfirmation(pLocalUser, null, instructionID)); } if (pLocalUser.GetType() == typeof(NetComServer)) { (pLocalUser as NetComServer).Send(new InstructionLibraryEssentials.ReceptionConfirmation(pLocalUser, (pLocalUser as NetComServer).ConnectedClients[pReceptionSocket], instructionID)); } continue; } } // Check instructionset-version if (ForceInstructionsetVersion && InstructionBase.InstructionSetVersion != instructionsetVersion) { throw new NetComVersionException($"*** The received package uses a different verion of the Instruction-Set! Local version: {InstructionBase.InstructionSetVersion} - Senders version: {instructionsetVersion} ***"); } // Check framework-version if (ForceFrameworkVersion && InstructionBase.FrameworkVersion != frameworkVersion) { throw new NetComVersionException($"*** The received package was built using a different verion of the Framework! Local version: {InstructionBase.FrameworkVersion} - Senders version: {frameworkVersion} ***"); } // Check signature if (rsaEncoded && !RSAHandler.Verify(publicKey, signaturePlain, signatureRSA)) { throw new NetComSignatureException("*** The received packets signature is invalid! ***"); } if (pServerClientList != null) { // Server -> Assign received data to clientlist pServerClientList[pReceptionSocket].SetUserData(username, password, publicKey); if (instruction != typeof(InstructionLibraryEssentials.KeyExchangeClient2Server).AssemblyQualifiedName && instruction != typeof(InstructionLibraryEssentials.ReceptionConfirmation).AssemblyQualifiedName && !pServerClientList[pReceptionSocket].Authenticate(password)) { throw new NetComAuthenticationException("*** Authentication failed! Wrong username / password ***"); } user = pServerClientList[pReceptionSocket]; } else { // Client -> Ignore authentication-data user = new NetComUser(); user.SetUserData(username, password, publicKey); } try { if (instruction == typeof(InstructionLibraryEssentials.ReceptionConfirmation).AssemblyQualifiedName) { retInstr.Add((InstructionBase)Activator.CreateInstance(Type.GetType(instruction), user, pLocalUser, value)); } else if (value == null && parameters.Count == 0) { retInstr.Add((InstructionBase)Activator.CreateInstance(Type.GetType(instruction), user, pLocalUser)); } else if (parameters.Count == 0) { retInstr.Add((InstructionBase)Activator.CreateInstance(Type.GetType(instruction), user, pLocalUser, value)); } else { retInstr.Add((InstructionBase)Activator.CreateInstance(Type.GetType(instruction), user, pLocalUser, value, parameters.ToArray())); } // Increment the total receive counter (pLocalUser as NetComOperator).TotalReceiveCounter++; // Send confirmation (if the instruction is not a confirmation itself) if (instruction != typeof(InstructionLibraryEssentials.ReceptionConfirmation).AssemblyQualifiedName) { (pLocalUser as NetComOperator).InstructionLogIncomming.Add(instructionID); if (pLocalUser.GetType() == typeof(NetComClient)) { (pLocalUser as NetComClient).Send(new InstructionLibraryEssentials.ReceptionConfirmation(pLocalUser, null, instructionID)); } if (pLocalUser.GetType() == typeof(NetComServer)) { (pLocalUser as NetComServer).Send(new InstructionLibraryEssentials.ReceptionConfirmation(pLocalUser, (pLocalUser as NetComServer).ConnectedClients[pReceptionSocket], instructionID)); } } } catch (Exception ex) { (pLocalUser as NetComOperator).Debug("Could not recreate the instruction.", DebugType.Error); if ((pLocalUser as NetComOperator).ShowExceptions) { (pLocalUser as NetComOperator).Debug($"({ex.GetType().Name}) {ex.Message}", DebugType.Exception); } } } } return(retInstr.ToArray()); }
public KeyExchangeServer2Client(NetComUser pSender, NetComUser pReceiver) : base(pSender, pReceiver, pSender.RSAKeys.PublicKey, null) { }
public KeyExchangeServer2Client(NetComUser pSender, NetComUser pReceiver, string pValue) : base(pSender, pReceiver, pValue, null) { }
public ToConsoleColored(NetComUser pSender, NetComUser pReceiver, string pValue, ConsoleColor pForegroundColor, ConsoleColor pBackgroundColor) : base(pSender, pReceiver, pValue, null) { object[] prm = new object[2]; switch (pForegroundColor) { case ConsoleColor.Black: prm[0] = "FG0"; break; case ConsoleColor.Blue: prm[0] = "FG1"; break; case ConsoleColor.Cyan: prm[0] = "FG2"; break; case ConsoleColor.DarkBlue: prm[0] = "FG3"; break; case ConsoleColor.DarkCyan: prm[0] = "FG4"; break; case ConsoleColor.DarkGray: prm[0] = "FG5"; break; case ConsoleColor.DarkGreen: prm[0] = "FG6"; break; case ConsoleColor.DarkMagenta: prm[0] = "FG7"; break; case ConsoleColor.DarkRed: prm[0] = "FG8"; break; case ConsoleColor.DarkYellow: prm[0] = "FG9"; break; case ConsoleColor.Gray: prm[0] = "FGA"; break; case ConsoleColor.Green: prm[0] = "FGB"; break; case ConsoleColor.Magenta: prm[0] = "FGC"; break; case ConsoleColor.Red: prm[0] = "FGD"; break; case ConsoleColor.White: prm[0] = "FGE"; break; case ConsoleColor.Yellow: prm[0] = "FGF"; break; } switch (pBackgroundColor) { case ConsoleColor.Black: prm[1] = "BG0"; break; case ConsoleColor.Blue: prm[1] = "BG1"; break; case ConsoleColor.Cyan: prm[1] = "BG2"; break; case ConsoleColor.DarkBlue: prm[1] = "BG3"; break; case ConsoleColor.DarkCyan: prm[1] = "BG4"; break; case ConsoleColor.DarkGray: prm[1] = "BG5"; break; case ConsoleColor.DarkGreen: prm[1] = "BG6"; break; case ConsoleColor.DarkMagenta: prm[1] = "BG7"; break; case ConsoleColor.DarkRed: prm[1] = "BG8"; break; case ConsoleColor.DarkYellow: prm[1] = "BG9"; break; case ConsoleColor.Gray: prm[1] = "BGA"; break; case ConsoleColor.Green: prm[1] = "BGB"; break; case ConsoleColor.Magenta: prm[1] = "BGC"; break; case ConsoleColor.Red: prm[1] = "BGD"; break; case ConsoleColor.White: prm[1] = "BGE"; break; case ConsoleColor.Yellow: prm[1] = "BGF"; break; } parameters = prm; }
public ToConsoleColored(NetComUser pSender, NetComUser pReceiver, string pValue, object[] pParameters) : base(pSender, pReceiver, pValue, pParameters) { }
public ToNetComDebug(NetComUser pSender, NetComUser pReceiver, string pValue) : base(pSender, pReceiver, pValue, null) { }
public ReceptionConfirmation(NetComUser pSender, NetComUser pReceiver, string pInstructionID) : base(pSender, pReceiver, pInstructionID, null) { }
public NofityIcon(NetComUser pSender, NetComUser pReceiver, string pValue, object[] pParameters) : base(pSender, pReceiver, pValue, pParameters) { }
public SimpleMessageBox(NetComUser pSender, NetComUser pReceiver, string pMessage) : base(pSender, pReceiver, pMessage, null) { }
public TestSample(NetComUser pSender, NetComUser pReceiver) : base(pSender, pReceiver, null, null) { }