internal void SendChatMsg(GuiChatLobby cl, string inMsg = "") { string text = (inMsg == "") ? _b.GUI.tb_chatMsg.Text : inMsg; ChatId id = new ChatId(); if (cl.ID == BROADCAST) { id.chat_id = ""; id.chat_type = ChatType.TYPE_GROUP; } else { id.chat_id = cl.ID; id.chat_type = ChatType.TYPE_LOBBY; } ChatMessage msg = new ChatMessage(); msg.id = id; msg.msg = text; msg.peer_nickname = _nick; msg.send_time = (uint)DateTime.Now.Second; _b.RPC.ChatSendMsg(msg); if (cl.ID != BROADCAST) // needed ?! { AddMsgToLobby(cl.ID, DateTime.Now.ToLongTimeString() + " - " + _nick + " > " + text + "\n"); } if (inMsg == "") { _b.GUI.tb_chatMsg.Clear(); } }
/// <summary> /// joins/leaves selected lobby /// </summary> /// <param name="action">true = join; false = leave</param> /// <param name="index">lobby index</param> internal CheckState JoinLeaveChatLobby(JoinLeaveAction action, int index) { CheckState state = CheckState.Unchecked; GuiChatLobby cl = new GuiChatLobby(); if (GetLobbyByListIndex(index, out cl)) { if ((action == JoinLeaveAction.join || action == JoinLeaveAction.toggle) && !cl.Joined) // join lobby { _b.RPC.ChatJoinLeaveLobby(RequestJoinOrLeaveLobby.LobbyAction.JOIN_OR_ACCEPT, cl.ID); cl.Joined = true; cl.Lobby.lobby_state = ChatLobbyInfo.LobbyState.LOBBYSTATE_JOINED; state = CheckState.Checked; } else if ((action == JoinLeaveAction.leave || action == JoinLeaveAction.toggle) && cl.Joined) // leave lobby { _b.RPC.ChatJoinLeaveLobby(RequestJoinOrLeaveLobby.LobbyAction.LEAVE_OR_DENY, cl.ID); cl.Joined = false; cl.Lobby.lobby_state = ChatLobbyInfo.LobbyState.LOBBYSTATE_VISIBLE; state = CheckState.Unchecked; } // save changes _chatLobbies[cl.ID] = cl; CheckChatRegistration(); } return(state); }
internal void AddMsgToLobby(string ID, string msg) { GuiChatLobby cl = _chatLobbies[ID]; cl.ChatText += msg; _chatLobbies[ID] = cl; if (_b.GUI.clb_chatLobbies.SelectedIndex == cl.Index) { //SetChatText(ID); _reDrawChat = true; } }
private void AutoAnswer(ChatMessage response, GuiChatLobby cl) { string[] msgOUT = _b.AutoResponse.Process(response, cl); if (msgOUT != null) { foreach (string s in msgOUT) { if (s != "") { SendChatMsg(cl, s); } } } }
internal bool GetLobbyByListIndex(int index, out GuiChatLobby lobby) { GuiChatLobby[] values = new GuiChatLobby[_chatLobbies.Values.Count]; _chatLobbies.Values.CopyTo(values, 0); foreach (GuiChatLobby l in values) { if (l.Index == index) { lobby = l; return(true); } } lobby = default(GuiChatLobby); return(false); }
private void bt_chatSend_Click(object sender, EventArgs e) { if (tb_chatMsg.Text != "") { // get chat lobby int index = _b.GUI.clb_chatLobbies.SelectedIndex; if (index >= 0 && _b.GUI.clb_chatLobbies.GetItemChecked(index)) { GuiChatLobby cl = new GuiChatLobby(); if (_b.ChatProcessor.GetLobbyByListIndex(index, out cl)) { _b.ChatProcessor.SendChatMsg(cl); } } } tb_chatMsg.Focus(); }
private void ProcessLobby(ChatLobbyInfo lobby) { string ID = lobby.lobby_id, nameToShow = ""; GuiChatLobby cl = new GuiChatLobby(); nameToShow = "[" + (lobby.no_peers <= 9 ? "0" : "") + lobby.no_peers + "] " + lobby.lobby_name + // when there is no topic don't add "-" (lobby.lobby_topic != "" ? " - " + lobby.lobby_topic : ""); if (_chatLobbies.ContainsKey(ID)) //update { System.Diagnostics.Debug.WriteLineIf(DEBUG, "updating lobby " + lobby.lobby_name + " - state " + lobby.lobby_state); System.Diagnostics.Debug.WriteLineIf(DEBUG, "user: "******" - names: " + lobby.nicknames.Count + " - friends: " + lobby.participating_friends.Count); cl = _chatLobbies[ID]; cl.Lobby = lobby; cl.ChatUser = lobby.nicknames; _chatLobbies[ID] = cl; _b.GUI.clb_chatLobbies.Items[cl.Index] = nameToShow; if (lobby.lobby_state == ChatLobbyInfo.LobbyState.LOBBYSTATE_INVITED && !cl.Joined) { _b.GUI.clb_chatLobbies.SetItemCheckState(cl.Index, CheckState.Indeterminate); } } else //new { System.Diagnostics.Debug.WriteLineIf(DEBUG, "adding lobby " + lobby.lobby_name + " - state " + lobby.lobby_state); System.Diagnostics.Debug.WriteLineIf(DEBUG, "user: "******" - names: " + lobby.nicknames.Count + " - friends: " + lobby.participating_friends.Count); cl.Lobby = lobby; cl.Index = (ushort)_b.GUI.clb_chatLobbies.Items.Count; cl.Joined = (lobby.lobby_state == ChatLobbyInfo.LobbyState.LOBBYSTATE_JOINED); cl.Unread = false; cl.ChatText = "======= " + DateTime.Now.ToLongDateString() + " - " + lobby.lobby_name + " =======\n"; cl.ChatUser = lobby.participating_friends; _b.GUI.clb_chatLobbies.Items.Add(nameToShow, cl.Joined); if (lobby.lobby_state == ChatLobbyInfo.LobbyState.LOBBYSTATE_INVITED) { _b.GUI.clb_chatLobbies.SetItemCheckState(cl.Index, CheckState.Indeterminate); } _chatLobbies.Add(cl.ID, cl); } }
private void NotifyAndSetCheckState() { GuiChatLobby[] values = new GuiChatLobby[_chatLobbies.Count]; _chatLobbies.Values.CopyTo(values, 0); foreach (GuiChatLobby lobby in values) { if (lobby.Lobby == null) { continue; } CheckState state = _b.GUI.clb_chatLobbies.GetItemCheckState(lobby.Index); if (lobby.Unread) { // unread messages if (state == CheckState.Indeterminate) { if (lobby.Joined) { state = CheckState.Checked; } else { state = CheckState.Unchecked; } } else { state = CheckState.Indeterminate; } _b.GUI.clb_chatLobbies.SetItemCheckState(lobby.Index, state); } else if (lobby.Lobby.lobby_state == ChatLobbyInfo.LobbyState.LOBBYSTATE_INVITED) { // invited by someone _b.GUI.clb_chatLobbies.SetItemCheckState(lobby.Index, (state == CheckState.Indeterminate) ? CheckState.Unchecked : CheckState.Indeterminate); } else { // nothing to notify - just set the correct CheckState _b.GUI.clb_chatLobbies.SetItemCheckState(lobby.Index, lobby.Joined ? CheckState.Checked : CheckState.Unchecked); } } }
/// <summary> /// prints the text from a lobby to screen (textbox) /// </summary> /// <param name="LobbyID">lobby ID</param> private void SetChatText(string LobbyID) { GuiChatLobby cl = _chatLobbies[LobbyID]; cl.Unread = false; // check of the history ist too long CheckHistoryLength(ref cl); _b.GUI.rtb_chat.Text = cl.ChatText; _b.GUI.rtb_chat.SelectionStart = _b.GUI.rtb_chat.Text.Length; _b.GUI.rtb_chat.ScrollToCaret(); _chatLobbies[LobbyID] = cl; if (cl.Joined && _b.GUI.clb_chatLobbies.GetItemCheckState(cl.Index) == CheckState.Indeterminate) { _b.GUI.clb_chatLobbies.SetItemCheckState(cl.Index, CheckState.Checked); } }
/// <summary> /// Checks all auto response items if any matches. /// </summary> /// <param name="msgIN">message to check</param> /// <param name="cl"></param> /// <returns>message(s)</returns> internal string[] Process(ChatMessage msgIN, GuiChatLobby cl) { // check if auto response is activated if (!_b.GUI.cb_chat_arEnable.Checked) { return(null); } // check if msg is too old System.Diagnostics.Debug.WriteLineIf(DEBUG, "rec msg: " + msgIN.send_time + " - now: " + Processor.conv_Date2Timestam(DateTime.UtcNow)); if (msgIN.send_time < Processor.conv_Date2Timestam(DateTime.UtcNow) - 60) { return(null); } // check if there are any items if (_items.Count == 0) { this.SetupBasicItems(); } List <string> msgOUT = new List <string>(); string s = ""; AutoResponseItem[] items = new AutoResponseItem[_items.Count]; _items.Values.CopyTo(items, 0); foreach (AutoResponseItem item in items) { if (item.IsActive() && !item.IsLobbyBlacklisted(cl.ID)) { s = item.Process(msgIN); } if (s != "") { msgOUT.Add(s); s = ""; } } return(msgOUT.ToArray()); }
internal void ChatLobbyIndexChange(int index) { if (index >= 0) { GuiChatLobby cl = new GuiChatLobby(); if (GetLobbyByListIndex(index, out cl)) { SetChatText(cl.ID); _b.GUI.clb_chatUser.Items.Clear(); foreach (string s in cl.ChatUser) { _b.GUI.clb_chatUser.Items.Add(s); } } else { _b.GUI.rtb_chat.Text = "ERROR: can't find GuiChatLobby at index " + index; } } }
internal void AddMsgToLobby(string ID, ChatMessage response) { System.Diagnostics.Debug.WriteLineIf(DEBUG, "Chat: PrintMsgToLobby ID: " + response.id); if (!_chatLobbies.ContainsKey(ID)) { // we don't know this lobby :S System.Diagnostics.Debug.WriteLineIf(DEBUG, "Chat: ID (" + response.id + ") is unknown"); return; } GuiChatLobby cl = _chatLobbies[ID]; string msg = Processor.RemoteTags(response.msg); System.Diagnostics.Debug.WriteLineIf(DEBUG, "Chat: lobby: " + cl.Lobby.lobby_name); System.Diagnostics.Debug.WriteLineIf(DEBUG, "Chat: msg: " + msg + " from " + response.peer_nickname); System.Diagnostics.Debug.WriteLineIf(DEBUG, "Chat: rec: " + response.recv_time + " send: " + response.send_time); // add "*time* - *nick* > *msg*" cl.ChatText += Processor.conv_Timestamp2Date(response.send_time).ToLocalTime().ToLongTimeString() + " - " + response.peer_nickname + " > " + msg + "\n"; _chatLobbies[ID] = cl; if (_b.GUI.clb_chatLobbies.SelectedIndex == cl.Index) { //SetChatText(ID); _reDrawChat = true; } else { if (!cl.Unread) { cl.Unread = true; _b.GUI.clb_chatLobbies.SetItemCheckState(cl.Index, CheckState.Indeterminate); _chatLobbies[ID] = cl; } } //AutoAnswer(Processor.RemoteTags(response.msg.msg)); AutoAnswer(response, cl); }
private void CheckHistoryLength(ref GuiChatLobby cl) { string history = cl.ChatText; int pos = 0; while (history.Length > Settings.MaxChatHistoryLength) { // cut of the first paragraph pos = history.IndexOf("\n") + 1; // + 1 for "\n" if (pos >= history.Length) { break; // don't remove everything! } history = history.Substring(pos, history.Length - pos); } // save changes if (history != cl.ChatText) { cl.ChatText = history; } }
internal void AddBroadcast() { if (!_chatLobbies.ContainsKey(BROADCAST)) { ChatLobbyInfo lobby = new ChatLobbyInfo(); lobby.lobby_name = "Broadcast"; lobby.lobby_id = BROADCAST; GuiChatLobby cl = new GuiChatLobby(); cl.Lobby = lobby; cl.Joined = true; cl.Unread = false; { _b.GUI.clb_chatLobbies.Items.Add(cl.Lobby.lobby_name, true); cl.Index = (ushort)_b.GUI.clb_chatLobbies.Items.IndexOf(cl.Lobby.lobby_name); } cl.ChatText = DateTime.Now.ToShortDateString() + " - " + DateTime.Now.ToShortTimeString() + "\n"; cl.ChatUser = new List <string> { }; _chatLobbies.Add(cl.ID, cl); CheckChatRegistration(); } }
private void bt_chatSend_Click(object sender, EventArgs e) { if (tb_chatMsg.Text != "") { // get chat lobby int index = _b.GUI.clb_chatLobbies.SelectedIndex; if (index >= 0 && _b.GUI.clb_chatLobbies.GetItemChecked(index)) { GuiChatLobby cl = new GuiChatLobby(); if (_b.ChatProcessor.GetLobbyByListIndex(index, out cl)) _b.ChatProcessor.SendChatMsg(cl); } } tb_chatMsg.Focus(); }
private void ProcessLobby(ChatLobbyInfo lobby) { string ID = lobby.lobby_id, nameToShow = ""; GuiChatLobby cl = new GuiChatLobby(); nameToShow = "[" + (lobby.no_peers <= 9 ? "0" : "") + lobby.no_peers + "] " + lobby.lobby_name + // when there is no topic don't add "-" (lobby.lobby_topic != "" ? " - " + lobby.lobby_topic : ""); if (_chatLobbies.ContainsKey(ID)) //update { System.Diagnostics.Debug.WriteLineIf(DEBUG, "updating lobby " + lobby.lobby_name + " - state " + lobby.lobby_state); System.Diagnostics.Debug.WriteLineIf(DEBUG, "user: "******" - names: " + lobby.nicknames.Count + " - friends: " + lobby.participating_friends.Count); cl = _chatLobbies[ID]; cl.Lobby = lobby; cl.ChatUser = lobby.participating_friends; _chatLobbies[ID] = cl; _b.GUI.clb_chatLobbies.Items[cl.Index] = nameToShow; if (lobby.lobby_state == ChatLobbyInfo.LobbyState.LOBBYSTATE_INVITED && !cl.Joined) _b.GUI.clb_chatLobbies.SetItemCheckState(cl.Index, CheckState.Indeterminate); } else //new { System.Diagnostics.Debug.WriteLineIf(DEBUG, "adding lobby " + lobby.lobby_name + " - state " + lobby.lobby_state); System.Diagnostics.Debug.WriteLineIf(DEBUG, "user: "******" - names: " + lobby.nicknames.Count + " - friends: " + lobby.participating_friends.Count); cl.Lobby = lobby; cl.Index = (ushort)_b.GUI.clb_chatLobbies.Items.Count; cl.Joined = (lobby.lobby_state == ChatLobbyInfo.LobbyState.LOBBYSTATE_JOINED); cl.Unread = false; cl.ChatText = "======= " + DateTime.Now.ToLongDateString() + " - " + lobby.lobby_name + " =======\n"; cl.ChatUser = lobby.participating_friends; _b.GUI.clb_chatLobbies.Items.Add(nameToShow, cl.Joined); if (lobby.lobby_state == ChatLobbyInfo.LobbyState.LOBBYSTATE_INVITED) _b.GUI.clb_chatLobbies.SetItemCheckState(cl.Index, CheckState.Indeterminate); _chatLobbies.Add(cl.ID, cl); } }
private void NotifyAndSetCheckState() { GuiChatLobby[] values = new GuiChatLobby[_chatLobbies.Count]; _chatLobbies.Values.CopyTo(values, 0); foreach (GuiChatLobby lobby in values) { if (lobby.Lobby == null) continue; CheckState state = _b.GUI.clb_chatLobbies.GetItemCheckState(lobby.Index); if (lobby.Unread) { // unread messages if (state == CheckState.Indeterminate) if (lobby.Joined) state = CheckState.Checked; else state = CheckState.Unchecked; else state = CheckState.Indeterminate; _b.GUI.clb_chatLobbies.SetItemCheckState(lobby.Index, state); } else if (lobby.Lobby.lobby_state == ChatLobbyInfo.LobbyState.LOBBYSTATE_INVITED) // invited by someone _b.GUI.clb_chatLobbies.SetItemCheckState(lobby.Index, (state == CheckState.Indeterminate) ? CheckState.Unchecked : CheckState.Indeterminate); else // nothing to notify - just set the correct CheckState _b.GUI.clb_chatLobbies.SetItemCheckState(lobby.Index, lobby.Joined ? CheckState.Checked : CheckState.Unchecked); } }
private void CheckHistoryLength(ref GuiChatLobby cl) { string history = cl.ChatText; int pos = 0; while (history.Length > Settings.MaxChatHistoryLength) { // cut of the first paragraph pos = history.IndexOf("\n") + 1; // + 1 for "\n" if (pos >= history.Length) break; // don't remove everything! history = history.Substring(pos, history.Length - pos); } // save changes if(history != cl.ChatText) cl.ChatText = history; }
private void AutoAnswer(ChatMessage response, GuiChatLobby cl) { string[] msgOUT = _b.AutoResponse.Process(response, cl); if (msgOUT != null) foreach (string s in msgOUT) if (s != "") SendChatMsg(cl, s); }
internal void SendChatMsg(GuiChatLobby cl, string inMsg = "") { string text = (inMsg == "") ? _b.GUI.tb_chatMsg.Text : inMsg; ChatId id = new ChatId(); if (cl.ID == BROADCAST) { id.chat_id = ""; id.chat_type = ChatType.TYPE_GROUP; } else { id.chat_id = cl.ID; id.chat_type = ChatType.TYPE_LOBBY; } ChatMessage msg = new ChatMessage(); msg.id = id; msg.msg = text; msg.peer_nickname = _nick; msg.send_time = (uint)DateTime.Now.Second; _b.RPC.ChatSendMsg(msg); if (cl.ID != BROADCAST) // needed ?! AddMsgToLobby(cl.ID, DateTime.Now.ToLongTimeString() + " - " + _nick + " > " + text + "\n"); if (inMsg == "") _b.GUI.tb_chatMsg.Clear(); }
/// <summary> /// joins/leaves selected lobby /// </summary> /// <param name="action">true = join; false = leave</param> /// <param name="index">lobby index</param> internal CheckState JoinLeaveChatLobby(JoinLeaveAction action, int index) { CheckState state = CheckState.Unchecked; GuiChatLobby cl = new GuiChatLobby(); if (GetLobbyByListIndex(index, out cl)) { if ((action == JoinLeaveAction.join || action == JoinLeaveAction.toggle) && !cl.Joined) // join lobby { _b.RPC.ChatJoinLeaveLobby(RequestJoinOrLeaveLobby.LobbyAction.JOIN_OR_ACCEPT, cl.ID); cl.Joined = true; cl.Lobby.lobby_state = ChatLobbyInfo.LobbyState.LOBBYSTATE_JOINED; state = CheckState.Checked; } else if ((action == JoinLeaveAction.leave || action == JoinLeaveAction.toggle) && cl.Joined) // leave lobby { _b.RPC.ChatJoinLeaveLobby(RequestJoinOrLeaveLobby.LobbyAction.LEAVE_OR_DENY, cl.ID); cl.Joined = false; cl.Lobby.lobby_state = ChatLobbyInfo.LobbyState.LOBBYSTATE_VISIBLE; state = CheckState.Unchecked; } // save changes _chatLobbies[cl.ID] = cl; CheckChatRegistration(); } return state; }
internal bool GetLobbyByListIndex(int index, out GuiChatLobby lobby) { GuiChatLobby[] values = new GuiChatLobby[_chatLobbies.Values.Count]; _chatLobbies.Values.CopyTo(values, 0); foreach (GuiChatLobby l in values) { if (l.Index == index) { lobby = l; return true; } } lobby = default(GuiChatLobby); return false; }
internal void ChatLobbyIndexChange(int index) { if (index >= 0) { GuiChatLobby cl = new GuiChatLobby(); if (GetLobbyByListIndex(index, out cl)) { SetChatText(cl.ID); _b.GUI.clb_chatUser.Items.Clear(); foreach (string s in cl.ChatUser) _b.GUI.clb_chatUser.Items.Add(s); } else _b.GUI.rtb_chat.Text = "ERROR: can't find GuiChatLobby at index " + index; } }
internal void AddBroadcast() { if (!_chatLobbies.ContainsKey(BROADCAST)) { ChatLobbyInfo lobby = new ChatLobbyInfo(); lobby.lobby_name = "Broadcast"; lobby.lobby_id = BROADCAST; GuiChatLobby cl = new GuiChatLobby(); cl.Lobby = lobby; cl.Joined = true; cl.Unread = false; { _b.GUI.clb_chatLobbies.Items.Add(cl.Lobby.lobby_name, true); cl.Index = (ushort)_b.GUI.clb_chatLobbies.Items.IndexOf(cl.Lobby.lobby_name); } cl.ChatText= DateTime.Now.ToShortDateString() + " - " + DateTime.Now.ToShortTimeString() + "\n"; cl.ChatUser = new List<string> { }; _chatLobbies.Add(cl.ID, cl); CheckChatRegistration(); } }