示例#1
0
        private async void SendFrame(Command command, ServerEvent e, object obj)
        {
            PipeFrame    frame   = new PipeFrame();
            EventPayload payload = new EventPayload(nonce);

            payload.Command = command;
            payload.Event   = e;
            Ready ready = new Ready();

            payload.Data = JObject.FromObject(obj);
            using (MemoryStream stream = new MemoryStream())
            {
                //Write the stream and the send it to the pipe
                frame.Opcode = Opcode.Frame;
                frame.SetObject(payload);
                frame.WriteStream(stream);
                frame.Opcode = Opcode.Frame;
                //Get the bytes and send it
                byte[] bytes = stream.ToArray();
                await server.SendToAllAsync(bytes);
            }
            nonce++;
        }
示例#2
0
 private async void HandleMessage(PipeFrame frame)
 {
     Console.ForegroundColor = ConsoleColor.Gray;
     if (frame.Opcode == Opcode.Handshake)
     {
         //Respond with handshake
         Console.WriteLine("Sending handshake response");
         HandshakeFrame handshakeFrame = JsonConvert.DeserializeObject <HandshakeFrame>(frame.Message);
         SetAppId?.Invoke(null, handshakeFrame.client_id);
         Ready.Data ready = new Ready.Data()
         {
             Config = new Ready.Config()
             {
                 APIendpoint = "//discordapp.com/api",
                 CdnHost     = "cdn.discordapp.com",
                 Environment = "production"
             },
             User = new Ready.User()
             {
                 Avatar        = "123",
                 Bot           = false,
                 Discriminator = "8813",
                 Id            = "123",
                 Username      = "******"
             },
             Version = 1
         };
         SendFrame(Command.Dispatch, ServerEvent.Ready, ready);
     }
     else if (frame.Opcode == Opcode.Frame)
     {
         var frameMessage = JsonConvert.DeserializeObject <FrameMessage>(frame.Message);
         MessageReceived?.Invoke(null, frameMessage.Args.Activity);
     }
     Console.ForegroundColor = ConsoleColor.White;
 }