Пример #1
0
        public async Task <MessagePostResponse> PostMessage(ClientPlanetMessage msg)
        {
            //ClientMessage msg = JsonConvert.DeserializeObject<ClientMessage>(json);

            if (msg == null)
            {
                return(new MessagePostResponse(false, "Malformed message.", 0));
            }

            ulong channel_id = msg.ChannelId;

            if (channelIndexes.ContainsKey(channel_id))
            {
                channelIndexes[channel_id] += 1;
            }
            else
            {
                channelIndexes.Add(channel_id, 0);
            }

            // Get index for message
            ulong index = channelIndexes[channel_id];

            msg.Index = index;

            await MessageHub.Current.Clients.Group(channel_id.ToString()).SendAsync("Relay", msg.Content);

            return(new MessagePostResponse(true, "Test", index));
        }
Пример #2
0
        public IEnumerable <ClientPlanetMessage> GetMessages(ulong channel_id)
        {
            Console.WriteLine(channel_id);

            ulong channelId = 1;

            ClientPlanetMessage welcome = new ClientPlanetMessage()
            {
                ChannelId = channelId,
                Content   = "Welcome back."
            };

            messageCache.Add(welcome);

            return(messageCache.TakeLast(10).ToList());
        }
Пример #3
0
        public async Task OnMessageRecieve(string json)
        {
            ClientPlanetMessage message = Newtonsoft.Json.JsonConvert.DeserializeObject <ClientPlanetMessage>(json);

            //Console.WriteLine("RECIEVE: ");
            //Console.WriteLine(json);

            //Console.WriteLine($"Recieved message {message.Message_Index} from channel {message.Channel_Id}.");

            if (!OpenPlanetChatChannels.ContainsKey(message.Channel_Id))
            {
                Console.WriteLine("Error: Recieved a message for a closed channel.");
            }

            foreach (ChannelWindowComponent window in OpenPlanetChatWindows.Where(x => x.Channel.Id == message.Channel_Id))
            {
                await window.OnRecieveMessage(message);
            }
        }
Пример #4
0
 /// <summary>
 /// Returns true if the client message matches this server message
 /// </summary>
 public bool EqualsMessage(ClientPlanetMessage message)
 {
     return(Hash == message.GetHash());
 }