protected void Awake() { ReceiveMessageEvent = new ChatMessageEvent(); DeleteMessageEvent = new RemoveMessageEvent(); Messages = new ObservableCollection <ChatMessageData>(); Messages.CollectionChanged += HandleCollectionChange; }
private void OnChatMessage(ref ChatMsg message, ref bool cancel) { // TODO player manager to cache these objects var player = new Player { Name = message.CustomAuthorName, SteamId = message.Author }; var text = message.Text; if (_commands.IsCommand(text)) { _commands.Execute(player, text.TrimStart(CommandPrefix), s => SendMessageTo(s, player.SteamId)); cancel = true; } else { var e = new ChatMessageEvent(message.Author, message.CustomAuthorName, text); ChatMessageReceived?.Invoke(ref e); cancel |= e.IsCancelled; if (!cancel) { _chatLog.Info($"{e.SenderName}: {e.Content}"); } } }
private static void OnHelp(ChatMessageEvent p_Event, String p_Data) { var s_Command = p_Data.Trim(); if (String.IsNullOrWhiteSpace(s_Command)) { var s_Commands = "Available commands: "; foreach (var s_Pair in m_ChatCommands) { if (!s_Pair.Value.MainInstance) continue; s_Commands += s_Pair.Value.Command + " • "; } SendChatMessage(s_Commands.Substring(0, s_Commands.Length - 3)); SendChatMessage("For detailed information on a command use " + SettingsManager.CommandPrefix() + "help [command]."); return; } ChatCommand s_ChatCommand; if (!m_ChatCommands.TryGetValue(s_Command, out s_ChatCommand)) { SendChatMessage("Command not found."); return; } // Print command description. SendChatMessage(SettingsManager.CommandPrefix() + s_ChatCommand.Command + s_ChatCommand.Description); // Print command aliases. if (s_ChatCommand.Aliases.Count == 0) return; var s_Aliases = "Aliases: "; foreach (var s_Alias in s_ChatCommand.Aliases) s_Aliases += s_Alias + " • "; SendChatMessage(s_Aliases.Substring(0, s_Aliases.Length - 3)); }
public void SendChatMessage(ChatMessage message) { int count = (message.links == null) ? 0 : message.links.Count; object[] links = null; if (count == 0) { links = new object[] { }; } else { links = new object[count]; for (int i = 0; i < count; i++) { links[i] = message.links[i].GetInfo(); } } ChatMessageEvent chatEvent = new ChatMessageEvent { CharacterID = message.targetCharacterID, ChatGroup = message.chatGroup, Links = links, Message = message.message, MessageID = message.messageID, SourceCharacterID = message.sourceCharacterID, SourceLogin = message.sourceLogin, TargetLogin = message.targetLogin, sourceCharacterName = message.sourceCharacterName, senderIconId = message.senderIconId, time = message.time }; EventData data = new EventData((byte)SelectCharacterEventCode.ChatMessageEvent, chatEvent); SendEvent(data, new SendParameters()); }
/// <summary> /// Get the next chat message from the channel. /// </summary> /// <returns>The chat message info.</returns> public async Task <BaseEvent> GetNextChatMessageAsync() { BaseEvent chatMessageInfo = null; // we'll just keep trying until we get a chat message using (var ts = new CancellationTokenSource()) { while (chatMessageInfo == null) { try { var nextMessage = await RecieveMessageAsync(ts.Token); var rawJson = DeserializeMessage <JObject>(nextMessage); Console.WriteLine(rawJson.ToString()); chatMessageInfo = rawJson.ToObject <BaseEvent>(); if (string.CompareOrdinal(chatMessageInfo.type, BaseEvent.Type) != 0) { chatMessageInfo = null; } else if (string.CompareOrdinal(chatMessageInfo.Event, ChatDeleteMessageEvent.EventType) == 0) { chatMessageInfo = rawJson.ToObject <Messages.ChatDeleteMessageEvent>(); } else if (string.CompareOrdinal(chatMessageInfo.Event, ChatUserJoinEvent.EventType) == 0) { chatMessageInfo = rawJson.ToObject <Messages.ChatUserJoinEvent>(); } else if (string.CompareOrdinal(chatMessageInfo.Event, ChatUserLeaveEvent.EventType) == 0) { chatMessageInfo = rawJson.ToObject <Messages.ChatUserLeaveEvent>(); } else if (string.CompareOrdinal(chatMessageInfo.Event, ChatPollStartEvent.EventType) == 0) { chatMessageInfo = rawJson.ToObject <Messages.ChatPollStartEvent>(); } else if (string.CompareOrdinal(chatMessageInfo.Event, ChatPollEndEvent.EventType) == 0) { chatMessageInfo = rawJson.ToObject <Messages.ChatPollEndEvent>(); } else if (string.CompareOrdinal(chatMessageInfo.Event, ChatMessageEvent.EventType) == 0) { //chatMessageInfo = rawJson.ToObject<Messages.ChatMessageEvent>(); var chatEvent = new ChatMessageEvent { data = new ChatMessageInfo() { id = rawJson["data"]["id"].ToString(), user_id = uint.Parse(rawJson["data"]["user_id"].ToString()), user_name = rawJson["data"]["user_name"].ToString() } }; var messages = rawJson["data"]["message"]["message"].Children(); chatEvent.data.message = new ChatMessagesData(); foreach (var result in messages) { var data = result.ToObject <ChatMessageData>(); switch (data.type) { case ChatMessageType.emoticon: chatEvent.data.message.message.Add(result.ToObject <ChatMessageEmoteData>()); break; case ChatMessageType.tag: chatEvent.data.message.message.Add(result.ToObject <ChatMessageTagData>()); break; case ChatMessageType.image: case ChatMessageType.link: chatEvent.data.message.message.Add(result.ToObject <ChatMessageUrlData>()); break; default: chatEvent.data.message.message.Add(data); break; } } chatMessageInfo = chatEvent; } else { // we didn't match a type we care about, just throw it away chatMessageInfo = null; } } catch (Exception ex) { Console.Error.WriteLine(ex.Message); // if anything goes wrong kill the message chatMessageInfo = null; } } } return(chatMessageInfo); }
public void OnChatPacket(PacketReader reader) { int messageNum = reader.ReadInt16(); reader.ReadString(4); // Language byte[] packet = reader.GetData(); switch (messageNum) { case 0x25: { int messageType = reader.ReadInt16(); string username = reader.ReadUnicodeString(); string message = reader.ReadUnicodeString(); Match matches = Regex.Match(message, "{(.*)}\\s+(.*)"); if (matches.Success) { string channel = matches.Groups[1].Value; string text = matches.Groups[2].Value; Messages.Add(new ChatMessage { Username = username, Channel = channel, Text = text }); ChatMessageEvent?.Invoke(username, channel, text); } break; } case 0x3e8: { string channel = reader.ReadUnicodeString(); if (!Channels.Contains(channel)) { Channels.Add(channel); ChannelCreatedEvent?.Invoke(channel); } break; } case 0x3e9: { string channel = reader.ReadUnicodeString(); if (Channels.Contains(channel)) { Channels.Remove(channel); ChannelRemovedEvent?.Invoke(channel); } break; } case 0x3ee: { reader.ReadInt16(); string userName = reader.ReadUnicodeString(); if (!Users.Contains(userName)) { Users.Add(userName); UserJoinedEvent?.Invoke(userName, string.Empty); } break; } case 0x3ef: { string userName = reader.ReadUnicodeString(); if (Users.Contains(userName)) { Users.Remove(userName); UserLeftEvent?.Invoke(userName, string.Empty); } break; } case 0x3f1: { CurrentChannel = reader.ReadUnicodeString(); JoinedChatChannelEvent?.Invoke(CurrentChannel); break; } case 0x3f0: { Users.Clear(); ClearUsersEvent?.Invoke(); break; } case 0x3f4: { LeftChatChannelEvent?.Invoke(CurrentChannel); CurrentChannel = null; break; } // ReSharper disable once RedundantEmptySwitchSection default: break; } }
public static void Init() { CallResults = new Dictionary <Type, Action <SteamAPICall_t> >(); CallResults.Add(typeof(LobbyMatchList_t), (SteamAPICall_t cb) => lobbyList.Set(cb)); CallResults.Add(typeof(LobbyEnter_t), (SteamAPICall_t cb) => lobbyEnter.Set(cb)); CallResults.Add(typeof(LobbyCreated_t), (SteamAPICall_t cb) => lobbyCreate.Set(cb)); CallResults.Add(typeof(PersonaStateChange_t), (SteamAPICall_t cb) => personaStateChange.Set(cb)); //init callbacks lobbyList = CallResult <LobbyMatchList_t> .Create((cb, failure) => { if (failure) { #if UNITY_EDITOR Debug.Log("Failed to received lobby list"); #endif return; } if (LobbyListEvent != null) { LobbyListEvent.Invoke(cb); } }); lobbyEnter = CallResult <LobbyEnter_t> .Create((cb, failure) => { if (failure) { #if UNITY_EDITOR Debug.Log("Failed to enter the specified lobby"); #endif return; } if (LobbyEnterEvent != null) { LobbyEnterEvent.Invoke(cb); } }); lobbyCreate = CallResult <LobbyCreated_t> .Create((cb, failure) => { if (failure) { #if UNITY_EDITOR Debug.Log("Failed to create a lobby"); #endif return; } #if UNITY_EDITOR Debug.Log("Lobby creation resulted with: " + cb.m_eResult.ToString()); #endif if (LobbyCreateEvent != null) { LobbyCreateEvent.Invoke(cb); } }); personaStateChange = CallResult <PersonaStateChange_t> .Create((cb, failure) => { if (PersonaStateChangeEvent != null) { PersonaStateChangeEvent.Invoke(cb); } }); chatMessage = Callback <LobbyChatMsg_t> .Create(cb => { if (ChatMessageEvent != null) { ChatMessageEvent.Invoke(cb); } }); chatUpdate = Callback <LobbyChatUpdate_t> .Create(cb => { if (ChatUpdateEvent != null) { ChatUpdateEvent.Invoke(cb); } }); lobbyInvite = Callback <GameLobbyJoinRequested_t> .Create(cb => { if (LobbyInviteEvent != null) { LobbyInviteEvent.Invoke(cb); } }); lobbyDataUpdate = Callback <LobbyDataUpdate_t> .Create(cb => { if (LobbyDataUpdateEvent != null) { LobbyDataUpdateEvent.Invoke(cb); } }); sessionRequest = Callback <P2PSessionRequest_t> .Create(cb => { if (AcceptP2PEvent != null) { AcceptP2PEvent.Invoke(cb); } }); p2pFail = Callback <P2PSessionConnectFail_t> .Create(cb => { if (P2PFailEvent != null) { P2PFailEvent.Invoke(cb); } }); }
private static void OnAbout(ChatMessageEvent p_Event, String p_Data) { SendChatMessage("This broadcast is powered by GrooveCaster " + Application.GetVersion() + ". For more information visit http://orfeasz.github.io/GrooveCaster/."); }