private void OnMessageHubName(ref HubNameMessage arg) { }
protected override void ParseRaw(byte[] buffer, int offset, int length) { var received = _encoding.GetString(buffer, offset, length); if (!string.IsNullOrEmpty(_dataBuffer)) { received = _dataBuffer + received; _dataBuffer = null; } var commands = received.Split('|'); var processCount = commands.Length; if (!received.EndsWith("|")) { _dataBuffer = received.Substring(received.LastIndexOf('|') + 1); processCount--; } for (int i = 0; i < processCount; i++) { var cmd = commands[i]; if (cmd.Length == 0) { continue; } if (IncomingMessage != null) { OnIncomingMessage(new MessageEventArgs { Message = cmd }); } if (cmd[0] == '$') { // command var spaceIndex = cmd.IndexOf(' '); var cmdName = spaceIndex == -1 ? cmd : cmd.Substring(0, spaceIndex); try { switch (cmdName) { case "$Hello": { var arg = HelloMessage.Parse(cmd); OnMessageHello(ref arg); } break; case "$HubName": { var arg = HubNameMessage.Parse(cmd); OnMessageHubName(ref arg); } break; case "$Lock": { var arg = LockMessage.Parse(cmd); OnMessageLock(ref arg); } break; case "$Search": { var arg = SearchMessage.Parse(cmd); OnMessageSearch(ref arg); } break; case "$ConnectToMe": { var arg = ConnectToMeMessage.Parse(cmd); var ea = new OutgoingConnectionRequestEventArgs { Message = arg }; OnOutgoingConnectionRequest(ea); } break; case "$RevConnectToMe": { var arg = RevConnectToMeMessage.Parse(cmd); var ea = new IncomingConnectionRequestEventArgs { Message = arg }; OnIncomingConnectionRequest(ea); if (!string.IsNullOrEmpty(ea.LocalAddress)) { SendMessage( new ConnectToMeMessage { RecipientNickname = arg.SenderNickname, SenderAddress = ea.LocalAddress }.Raw); } } break; case "$GetPass": { OnMessageGetPass(); } break; case "$MyINFO": { var arg = MyINFOMessage.Parse(cmd); OnMessageMyINFO(arg); } break; case "$Quit": { var arg = QuitMessage.Parse(cmd); OnMessageQuit(arg); } break; case "$SR": { var arg = SRMessage.Parse(cmd); OnMessageSR(arg); } break; case "$UserIP": { var arg = UserIPMessage.Parse(cmd); OnUserIPMessage(arg); } break; } } catch (Exception x) { Logger.Error("Error when trying to parse a command: " + x.Message); } } else { // chat message _lastChatMessage = cmd; OnChatMessage(new ChatMessageEventArgs { RawMessage = cmd }); } } }