public UserInfo(MyINFOMessage msg) { _nickname = msg.Nickname; _email = msg.Email; _share = msg.Share; _ip = ""; }
public void SendMyINFO(SendTransaction transaction = null) { var myInfo = new MyINFOMessage { Nickname = _currentUser.Nickname, Tag = string.Format("<{0},M:{1},H:{2},S:{3}{4}>", TagInfo.Version, Settings.PassiveMode ? "P" : "A", "0/0/0", "100", string.IsNullOrEmpty(TagInfo.City) ? "" : ",C:" + TagInfo.City), Connection = TagInfo.Connection, Flag = TagInfo.Flag, Share = _settings.FakeShare == 0 ? _currentUser.Share : _settings.FakeShare }; if (!myInfo.Equals(_prevMessage)) { if (transaction == null) { SendMessage(myInfo.Raw); } else { transaction.Send(myInfo.Raw); } } _prevMessage = myInfo; }
private void OnMessageMyINFO(MyINFOMessage arg) { var ui = new UserInfo(arg); Users.AddOrUpdate(arg.Nickname, ui, (key, prev) => ui); if (ui.Nickname == CurrentUser.Nickname) { Active = true; } }
private void HubConnectionConnectionStatusChanged(object sender, ConnectionStatusEventArgs e) { switch (e.Status) { case ConnectionStatus.Connecting: _lastChatMessage = null; break; case ConnectionStatus.Connected: RemoteAddressString = RemoteEndPoint.ToString(); break; case ConnectionStatus.Disconnected: _prevMessage = default(MyINFOMessage); if (!string.IsNullOrEmpty(_lastChatMessage)) { Logger.Info("Last hub chat message: {0}", _lastChatMessage); } Active = false; break; } }
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 }); } } }