Exemplo n.º 1
0
 public void SendMeClicking()
 {
     DeveOutgoingMessage outje = new DeveOutgoingMessage();
     outje.WriteInt32((int)ServerReceiveMessageType.NewButtonState); //Identifier for command message
     outje.WriteString(stringtosend);
     outje.WriteString(pressed.ToString());
     deveClient.Send(outje);
 }
        void kenServer_ReceivedMessage(object sender, ActionEventArgs e)
        {
            form.DebugMSG(e.Id + ": " + e.Action);
            switch (e.Action)
            {
                case "connected":
                    DeveClient deveClient = new DeveClient("localhost", 1337);
                    deveClient.Start();

                    DeveOutgoingMessage outje = new DeveOutgoingMessage();
                    outje.WriteInt32(0); //Join message
                    outje.WriteInt32(1); //Android
                    deveClient.Send(outje);

                    clients.Add(e.Id, deveClient);

                    break;
                case "closed":
                    clients[e.Id].Stop();

                    clients.Remove(e.Id);
                    //deveServer.messages.Enqueue(inc);

                    break;
                default:
                    DeveClient deveClientNow = clients[e.Id];

                    DeveOutgoingMessage outje2 = new DeveOutgoingMessage();
                    outje2.WriteInt32(1); //Identifier for command message
                    outje2.WriteString(e.Action);
                    deveClientNow.Send(outje2);

                    break;
            }
        }
Exemplo n.º 3
0
 public void SendMeClicking()
 {
     DeveOutgoingMessage outje = new DeveOutgoingMessage();
     outje.WriteInt32(1); //Identifier for command message
     outje.WriteString(stringtosend);
     deveClient.Send(outje);
 }
Exemplo n.º 4
0
 public void GoSender()
 {
     for (int i = 0; i < 1000; i++)
     {
         DeveOutgoingMessage msg = new DeveOutgoingMessage();
         msg.WriteString(i + "Hoi");
         deveClient.Send(msg);
         //Thread.Sleep(10);
     }
 }
Exemplo n.º 5
0
        public void Update(GameTime gameTime)
        {
            xSpeed = 0f;
            ySpeed = 0f;

            if (leftArrow)
            {
                xSpeed += -300f;
            }
            if (rightArrow)
            {
                xSpeed += 300f;
            }
            if (upArrown)
            {
                ySpeed += -300f;
            }
            if (downArrow)
            {
                ySpeed += 300f;
            }

            if (dirty)
            {

                DeveOutgoingMessage outje = new DeveOutgoingMessage();
                outje.WriteInt32((int)ServerSendMessageType.SetPlayerLocation);
                outje.WriteString(guid);
                outje.WriteInt32((int)posx);
                outje.WriteInt32((int)posy);
                outje.WriteInt32((int)xSpeed);
                outje.WriteInt32((int)ySpeed);

                game.SendToScreens(outje);

                dirty = false;
            }

            posx += xSpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
            posy += ySpeed * (float)gameTime.ElapsedGameTime.TotalSeconds;
        }
Exemplo n.º 6
0
 public void SendFile(String fileName)
 {
     DeveOutgoingMessage msg = new DeveOutgoingMessage(DeveMessageType.Data);
     msg.WriteString("file");
     using (FileStream read = new FileStream(fileName, FileMode.Open))
     {
         msg.WriteString(Path.GetFileName(fileName));
         msg.WriteInt32((int)read.Length);
         byte[] b = new byte[read.Length];
         read.Read(b, 0, (int)read.Length);
         msg.WriteBytes(b);
     }
     deveClient.Send(msg);
 }
Exemplo n.º 7
0
 private void button6_Click(object sender, EventArgs e)
 {
     DeveOutgoingMessage msg = new DeveOutgoingMessage(DeveMessageType.Data);
     msg.WriteString("teststuff");
     msg.WriteFloat(1.23456789f);
     msg.WriteUInt32(12020);
     deveClient.Send(msg);
 }
Exemplo n.º 8
0
        private void button4_Click(object sender, EventArgs e)
        {
            StringBuilder build = new StringBuilder();

            for (int i = 0; i < 999999; i++)
            {
                build.Append("S");
            }

            DeveOutgoingMessage msg = new DeveOutgoingMessage();
            msg.WriteString(":) " + build.ToString());
            deveClient.Send(msg);
        }
Exemplo n.º 9
0
 private void button1_Click(object sender, EventArgs e)
 {
     DeveOutgoingMessage devOut = new DeveOutgoingMessage();
     devOut.WriteString(textBox1.Text);
     deveClient.Send(devOut);
     textBox1.Text = "";
 }
Exemplo n.º 10
0
        public void Runner()
        {
            while (true)
            {
                DeveIncomingMessage inc;
                if ((inc = deveServer.ReadMessage()) != null)
                {
                    switch (inc.MessageType)
                    {
                        case DeveMessageType.KeepAlive:
                            break;
                        case DeveMessageType.Data:

                            int hetTypeMessage = inc.ReadInt32();
                            if (hetTypeMessage == 0) //Een join message
                            {
                                int hetTypeDevice = inc.ReadInt32();
                                if (hetTypeDevice == 0) //Een screen client
                                {
                                    DebugMSG("Het is een screen client :D:D:D");

                                    ScreenClientje screenClientje = new ScreenClientje(inc.Sender, curNumberOfScreen);
                                    screenClientjes.Add(inc.Sender, screenClientje);
                                    allClientjes.Add(inc.Sender, screenClientje);
                                    curNumberOfScreen++;

                                    SendNewAreas();
                                }
                                else if (hetTypeDevice == 1) //Android
                                {
                                    DebugMSG("Het is een Android :)");

                                    ControlClientje controlClientje = new ControlClientje(inc.Sender);
                                    controlClientjes.Add(inc.Sender, controlClientje);
                                    allClientjes.Add(inc.Sender, controlClientje);

                                    DeveOutgoingMessage outje = new DeveOutgoingMessage();
                                    outje.WriteInt32(1); //Add beestje bij alle screens
                                    outje.WriteString(controlClientje.guid);

                                    SendToScreens(outje);
                                }
                            }
                            else if (hetTypeMessage == 1) //Een message met button klik stuff
                            {

                                ControlClientje curControlClient = controlClientjes[inc.Sender];

                                String direction = inc.ReadString();

                                DebugMSG("Got message with: " + direction + " from: " + inc.Sender);

                                if (direction == "left")
                                {
                                    curControlClient.posx -= 50;
                                }
                                else if (direction == "right")
                                {
                                    curControlClient.posx += 50;
                                }
                                else if (direction == "up")
                                {
                                    curControlClient.posy -= 50;
                                }
                                else if (direction == "down")
                                {
                                    curControlClient.posy += 50;
                                }

                                DebugMSG("X: " + curControlClient.posx + " Y: " + curControlClient.posy);

                                DeveOutgoingMessage outje = new DeveOutgoingMessage();
                                outje.WriteInt32(3);
                                outje.WriteString(curControlClient.guid);
                                outje.WriteInt32(curControlClient.posx);
                                outje.WriteInt32(curControlClient.posy);

                                SendToScreens(outje);
                            }

                            break;
                        case DeveMessageType.StatusChanged:
                            byte newStatus = inc.ReadByte();
                            NetworkStatus ns = (NetworkStatus)newStatus;
                            switch (ns)
                            {
                                case NetworkStatus.Connected:

                                    DebugMSG("Er connect iets :O");
                                    break;
                                case NetworkStatus.Disconnected:

                                    if (controlClientjes.ContainsKey(inc.Sender))
                                    {
                                        ControlClientje controlClientje = controlClientjes[inc.Sender];
                                        DeveOutgoingMessage outje = new DeveOutgoingMessage();
                                        outje.WriteInt32(2);
                                        outje.WriteString(controlClientje.guid);
                                        SendToScreens(outje);

                                    }

                                    RemoveFromAllClientLists(inc.Sender);

                                    break;
                                default:
                                    break;
                            }
                            break;
                        default:
                            break;
                    }
                }
                Thread.Sleep(1);
            }
        }
Exemplo n.º 11
0
        public void Runner()
        {
            while (isRunning)
            {
                DeveIncomingMessage im = deveServer.ReadMessage();

                if (im == null)
                {
                    Thread.Sleep(1);
                }
                else
                {

                    switch (im.MessageType)
                    {
                        case DeveMessageType.Data:
                            try
                            {
                                String ding = im.ReadString();

                                if (ding.Equals("file"))
                                {
                                    String filename = im.ReadString();
                                    int fileSize = im.ReadInt32();
                                    byte[] fileData = im.ReadBytes(fileSize);

                                    this.Invoke(new MethodInvoker(delegate
                                    {
                                        this.listBox1.Items.Insert(0, "File ontvangen: " + filename + " writing...");
                                    }));

                                    using (FileStream stream = new FileStream(filename, FileMode.Create))
                                    {
                                        stream.Write(fileData, 0, fileSize);
                                    }

                                    this.Invoke(new MethodInvoker(delegate
                                    {
                                        this.listBox1.Items.Insert(0, "Done writing file");
                                    }));
                                }
                                else if (ding.Equals("teststuff"))
                                {
                                    this.Invoke(new MethodInvoker(delegate
                                    {
                                        this.listBox1.Items.Insert(0, "Just received a teststuff message: " + im.ReadFloat() + " and " + im.ReadUInt32());
                                    }));

                                }
                                else
                                {

                                    DeveOutgoingMessage outje = new DeveOutgoingMessage();
                                    outje.WriteString("Dit kreeg ik net: " + ding);
                                    deveServer.SendToAll(outje);

                                    //Console.WriteLine(ding);

                                    this.Invoke(new MethodInvoker(delegate
                                    {
                                        this.listBox1.Items.Insert(0, ding);
                                    }));
                                }
                            }
                            catch (Exception ezxz)
                            {
                                this.Invoke(new MethodInvoker(delegate
                                {
                                    this.listBox1.Items.Insert(0, ezxz.ToString());
                                }));
                            }
                            break;
                        case DeveMessageType.KeepAlive:
                            //doeniets :)
                            break;
                        case DeveMessageType.StatusChanged:
                            NetworkStatus status = (NetworkStatus)im.ReadByte();
                            Console.WriteLine("New network status voor " + im.Sender + ": " + status);
                            break;
                        default:

                            break;
                    }

                }
            }

            this.Invoke(new MethodInvoker(delegate
            {
                this.Close();
            }));
        }
Exemplo n.º 12
0
        public void HandleDataMessage(DeveIncomingMessage inc)
        {
            ServerReceiveMessageType messageType = (ServerReceiveMessageType)inc.ReadInt32();

            switch (messageType)
            {
                case ServerReceiveMessageType.LoginMessageScreenClient:
                    {
                        DebugMSG("Screen client connected");

                        int xscr = random.Next(100, 1000);
                        int yscr = random.Next(100, 1000);
                        int widthscr = inc.ReadInt32();
                        int heightscr = inc.ReadInt32();

                        ScreenClientje screenClientje = new ScreenClientje(new Rectangle(xscr, yscr, widthscr, heightscr), this, inc.Sender);
                        screenClientjes.Add(inc.Sender, screenClientje);
                        allClientjes.Add(inc.Sender, screenClientje);

                        DeveOutgoingMessage outje = new DeveOutgoingMessage();
                        outje.WriteInt32((int)ServerSendMessageType.MapString);
                        outje.WriteInt32(map[0].Count);
                        outje.WriteInt32(map.Count);
                        foreach (var mapline in map)
                        {
                            StringBuilder build = new StringBuilder();

                            foreach (String str in mapline)
                            {
                                build.Append(str);
                            }

                            outje.WriteString(build.ToString());
                        }

                        screenClientje.deveConnection.Send(outje);

                        foreach (var controlClientje in controlClientjes.Values)
                        {
                            outje = new DeveOutgoingMessage();
                            outje.WriteInt32((int)ServerSendMessageType.SpawnNewPlayer); //Add beestje bij alle screens
                            outje.WriteString(controlClientje.guid);

                            screenClientje.deveConnection.Send(outje);

                            outje = new DeveOutgoingMessage();
                            outje.WriteInt32((int)ServerSendMessageType.SetPlayerLocation);
                            outje.WriteString(controlClientje.guid);
                            outje.WriteInt32((int)controlClientje.posx);
                            outje.WriteInt32((int)controlClientje.posy);
                            outje.WriteInt32(0);
                            outje.WriteInt32(0);

                            screenClientje.deveConnection.Send(outje);
                        }
                    }
                    break;
                case ServerReceiveMessageType.LoginMessageControlClient:
                    {
                        DebugMSG("Het is een Android :)");

                        ControlClientje controlClientje = new ControlClientje(inc.Sender, this);
                        controlClientjes.Add(inc.Sender, controlClientje);
                        allClientjes.Add(inc.Sender, controlClientje);

                        DeveOutgoingMessage outje = new DeveOutgoingMessage();
                        outje.WriteInt32((int)ServerSendMessageType.SpawnNewPlayer); //Add beestje bij alle screens
                        outje.WriteString(controlClientje.guid);

                        SendToScreens(outje);
                    }
                    break;
                case ServerReceiveMessageType.NewButtonState:
                    {
                        ControlClientje curControlClient = controlClientjes[inc.Sender];

                        String direction = inc.ReadString();
                        String onOrOffString = inc.ReadString();
                        Boolean onOrOff = onOrOffString == "True";

                        DebugMSG("Got message with: " + direction + ": " + onOrOff);

                        if (direction == "left")
                        {
                            curControlClient.LeftArrow = onOrOff;
                        }
                        else if (direction == "right")
                        {
                            curControlClient.RightArrow = onOrOff;
                        }
                        else if (direction == "up")
                        {
                            curControlClient.UpArrown = onOrOff;
                        }
                        else if (direction == "down")
                        {
                            curControlClient.DownArrow = onOrOff;
                        }

                        //DebugMSG("X: " + curControlClient.posx + " Y: " + curControlClient.posy);

                        //DeveOutgoingMessage outje = new DeveOutgoingMessage();
                        //outje.WriteInt32((int)ServerSendMessageType.SetPlayerLocation);
                        //outje.WriteString(curControlClient.guid);
                        //outje.WriteInt32((int)curControlClient.posx);
                        //outje.WriteInt32((int)curControlClient.posy);

                        //SendToScreens(outje);
                        break;
                    }
                default:
                    DebugMSG("Unknown message type");
                    break;
            }
        }
Exemplo n.º 13
0
        private void UpdateNetwork(GameTime gameTime)
        {
            DeveIncomingMessage inc;
            while ((inc = deveServer.ReadMessage()) != null)
            {
                switch (inc.MessageType)
                {
                    case DeveMessageType.KeepAlive:
                        break;
                    case DeveMessageType.Data:
                        HandleDataMessage(inc);

                        break;
                    case DeveMessageType.StatusChanged:
                        byte newStatus = inc.ReadByte();
                        NetworkStatus ns = (NetworkStatus)newStatus;
                        switch (ns)
                        {
                            case NetworkStatus.Connected:

                                DebugMSG("Er connect iets :O");
                                break;
                            case NetworkStatus.Disconnected:

                                if (controlClientjes.ContainsKey(inc.Sender))
                                {
                                    ControlClientje controlClientje = controlClientjes[inc.Sender];
                                    DeveOutgoingMessage outje = new DeveOutgoingMessage();
                                    outje.WriteInt32((int)ServerSendMessageType.RemovePlayer);
                                    outje.WriteString(controlClientje.guid);
                                    SendToScreens(outje);

                                }

                                RemoveFromAllClientLists(inc.Sender);

                                break;
                            default:
                                break;
                        }
                        break;
                    default:
                        break;
                }
            }
        }