Example #1
0
        private void Client_OnPacketReceive(object sender, ReceivePacketArgs e)
        {
            var client = (Client)sender;

            if (e.Packet is AuthenticationPacket)
            {
                var account = ((AuthenticationPacket)e.Packet).Account;

                if (AllowedAccounts.Contains(account))
                {
                    IPacket packet = new InformationPacket();
                    packet.Execute(client);
                }
                else
                {
                    RemoveClient(client);
                }
            }
            else if (e.Packet is InformationPacket)
            {
                var info = ((InformationPacket)e.Packet);
                client.NetworkId = info.NetworkId;
                AddClient(client);
                OnClientConnect?.Invoke(this, new ClientStateChangeArgs(client.NetworkId, client, info));
            }
            else
            {
                OnClientPacketReceive?.Invoke(this, e);
            }
        }
Example #2
0
        private void handlePacket(int pid, Packet packet)
        {
            switch (pid)
            {
            case SynapseInfo.DISCONNECT_PACKET:
                DisconnectPacket disconnectPacket = (DisconnectPacket)packet;
                disconnectPacket.decode();
                this.loggedIn = false;

                Message("Disconnect received: " + disconnectPacket.message);

                break;

            case SynapseInfo.INFORMATION_PACKET:
                InformationPacket packetInformation = (InformationPacket)packet;
                packetInformation.decode();

                if (packetInformation.type == InformationPacket.TYPE_LOGIN)
                {
                    if (packetInformation.message == InformationPacket.INFO_LOGIN_SUCCESS)
                    {
                        this.loggedIn = true;
                        Message("Login sucess to " + address + ":" + port);
                    }
                    else
                    {
                        Message("Login failed to " + address + ":" + port);
                    }
                }
                else if (packetInformation.type == InformationPacket.TYPE_CLIENT_DATA)
                {
                    var clientHash = Newtonsoft.Json.JsonConvert.DeserializeObject(packetInformation.message);
                    //TODO: pass into ClientData object
                }

                break;

            case SynapseInfo.PLAYER_LOGIN_PACKET:
                PlayerLoginPacket packetLogin = (PlayerLoginPacket)packet;
                packetLogin.decode();
                Message("Player joining...");
                //  Message("Player UUID: " + packetLogin.uuid.ToString());
                Message("Player address: " + packetLogin.address);

                break;
            }
        }
Example #3
0
 public void AddPendingPacket(string port, InformationPacket ip)
 {
     pendingPackets.Enqueue(new PendingPacket(port, ip));
 }
Example #4
0
 public bool TrySend(InformationPacket ip)
 {
     Queue.Enqueue(ip);
     return(true);
 }
Example #5
0
 public void SetInitialData(InformationPacket ip)
 {
     Queue.Enqueue(ip);
 }
        protected override void OnPaint(PaintEventArgs e)
        {
            Graphics g          = e.Graphics;
            double   delta_time = (DateTime.Now - lastGUIUpdate).TotalMilliseconds;

            SetupGraphics(g, delta_time.ToString());

            if (!debug_break)
            {
                //DateTime tm_start = DateTime.Now;
                InformationPacket ip = Physics.Physics.Update(Puck, Puck, Table, delta_time);
                //times.Add((DateTime.Now - tm_start).TotalMilliseconds);
                //if (times.Count == 1000)
                //{
                //    tm.Stop();
                //    MessageBox.Show(times.Average().ToString());
                //}
                debugging_packets.Add(ip);
                if (debugging_packets.Count > 2)
                {
                    debugging_packets.RemoveAt(0);
                }
            }

            if (Puck.Location.X < 0 || Puck.Location.X > Table.Width || Puck.Location.Y < 0 || Puck.Location.Y > Table.Height)
            {
                tm.Stop();
                debug_break = true;
            }

            g.FillRectangle(Brushes.White, 0, 0, si(Table.Width), si(Table.Height));
            g.DrawRectangle(Pens.Black, 0, 0, si(Table.Width), si(Table.Height));

            foreach (Line w in Table.Walls)
            {
                DrawLine(g, w, Pens.Black);
            }

            foreach (Arc a in Table.Arcs)
            {
                DrawArc(g, a, Pens.Black);
            }

            g.FillEllipse(Brushes.Blue, getPuckRectangle(Puck));
            DrawLine(g, Puck.Path, Pens.Red);

            if (debug_break)
            {
                for (int j = 0; j < debugging_packets.Count; ++j)
                {
                    for (int i = 0; i < debugging_packets[j].Points.Count; ++i)
                    {
                        g.DrawRectangle(getFromInt(i), s(debugging_packets[j].Points[i].X), s(debugging_packets[j].Points[i].Y), 10, 10);
                    }
                    for (int i = 0; i < debugging_packets[j].Lines.Count; ++i)
                    {
                        DrawLine(g, debugging_packets[j].Lines[i], getFromInt(j));
                    }
                }
            }

            lastGUIUpdate = DateTime.Now;
            base.OnPaint(e);
        }
Example #7
0
 public bool TrySend(InformationPacket ip, bool ignoreClosed)
 {
     SentPackets.Add(ip);
     return(ResponseToUseForTrySend);
 }