Пример #1
0
        public void Listen()
        {
            while (true)
            {
                try
                {
                    while (true)
                    {
                        short header = br.ReadInt16();
                        Console.WriteLine((RecvHeaders)header);
                        if (handlers.ContainsKey(header))
                        {
                            //concept - handlers don't apply any changes to client themselves, just encapsulate info and return
                            RecievePacket p = handlers[header].handleData(br, bw, tcp);
                            recvPacket.Invoke(header, p);
                        }
                        else
                        {
                            Console.WriteLine("unknown header {0}", header);
                        }
                    }
                }
                catch (Exception e)
                {
                    Console.WriteLine(e);
                    Game.addToast("Connection to server has been closed");

                    lock (Game.ircLock)
                    {
                        if (Game.ircl != null)
                        {
                            Game.ircl.terminate();
                            Game.ircl = null;
                        }
                    }

                    Thread.Sleep(5000);
                    Console.WriteLine("attempting to reconnect...");
                    if (bw != null)
                    {
                        bw.Dispose();
                        bw = null;
                    }
                    if (br != null)
                    {
                        br.Dispose();
                        br = null;
                    }
                    if (tcp != null)
                    {
                        tcp.Close();
                        tcp = null;
                    }
                    while (tcp == null)
                    {
                        reconnectAttempts++;
                        if (reconnectAttempts >= 10)
                        {
                            break;
                        }
                        try
                        {
                            tcp = new TcpClient(host, port);
                            br  = new BinaryReader(tcp.GetStream());
                            bw  = new BinaryWriter(tcp.GetStream());
                        }
                        catch (Exception x)
                        {
                            if (tcp != null)
                            {
                                tcp.Close();
                            }
                            tcp = null;
                            Thread.Sleep(5000); //reconnect failed, sleep for another 5 secs
                            Console.WriteLine(x + "\nreconnect failed again, sleeping for another 5 secs");
                        }
                    }
                }
            }
            if (bw != null)
            {
                bw.Dispose();
                bw = null;
            }
            if (br != null)
            {
                br.Dispose();
                br = null;
            }
            if (tcp != null)
            {
                tcp.Close();
                tcp = null;
            }
            Console.WriteLine("stopped attempting reconnect");
        }
Пример #2
0
 static void c_recvPacket(short arg1, RecievePacket arg2)
 {
     Console.WriteLine(arg1 + " " + arg2.info[1]);
 }
Пример #3
0
 static void c_recvPacket(short arg1, RecievePacket arg2)
 {
     Console.WriteLine(arg1 + " " + arg2.info[1]);
 }
Пример #4
0
        void conn_recvPacket(short arg1, Client.RecievePacket arg2)
        {
            switch (arg1)
            {
            case (short)Pulse.Client.RecvHeaders.VERSION_CHECK:
                double serverversion = (double)arg2.info[0];
                if (serverversion > Config.Version)
                {
                    serverVer = serverversion;
                    verRemind = true;
                }
                else
                {
                    Console.WriteLine("running latest ver of pulse");
                }
                break;

            case (short)Pulse.Client.RecvHeaders.LOGIN_AUTH:
                byte login = (byte)arg2.info[0];
                if (login == 0)     //successful
                {
                    Account.currentAccount = new Account((string)arg2.info[2], (string)arg2.info[1], (string)arg2.info[3]);
                    //going to assume i can't set text from here because of gl context crap
                    //Game.game.Context.Ma
                    ((MenuScreen)screens["menuScreen"]).downloadAvatar();
                    lock (ircLock)
                    {
                        if (Game.ircl != null)
                        {
                            Game.ircl.terminate();
                            Game.ircl = null;
                        }
                        setMarquee         = true;
                        Game.ircl          = new Client.irc.IrcClient("pulse|" + Account.currentAccount.AccountName, Account.currentAccount.AccountName);
                        Game.ircl.realNick = Account.currentAccount.AccountName;
                        Game.pbox.setIrc(Game.ircl);
                    }
                }
                else
                {
                    Game.addToast("Login failed");
                }
                break;

            case (short)Pulse.Client.RecvHeaders.SPECTATE_RECORD:
                Config.Spectated = true;
                break;

            case (short)Pulse.Client.RecvHeaders.SPECTATE_END:
                Config.Spectated = false;
                break;

            case (short)Pulse.Client.RecvHeaders.SPECTATE_START:
                Config.SpectatedUser = (string)arg2.info[0];
                Config.Spectating    = true;
                int      diff = 0;
                SongInfo song = SongLibrary.findByMD5((string)arg2.info[1], ref diff);
                if (song != null)
                {
                    stopMedia = true;
                    IngameScreen temp = (IngameScreen)game.screens["ingameScreen"];
                    try
                    {
                        if (active.Music != null)
                        {
                            active.Music.pause();
                        }
                        Mods m = new Mods()
                        {
                            Flags  = (uint)((int)arg2.info[2]),
                            Scroll = (double)arg2.info[3]
                        };
                        temp.loadSong(SongLibrary.loadSong(song), diff, m, new Replay(), IngameScreen.PlayType.SPECTATE);
                        Game.setScreen(game.screens["ingameScreen"]);
                        Game.M.Music.pause();
                        Game.M.setSong(ref song);
                        Game.M.Visible = false;
                        Game.M.Enabled = false;
                        Client.PacketWriter.sendSpectateGotChart(Game.conn.Bw);
                    }
                    catch (Exception e)
                    {
                        Console.WriteLine(e.Message + e.StackTrace);
                    }
                }
                break;

            case (short)Pulse.Client.RecvHeaders.SPECTATE_CANCEL:
                if (active is IngameScreen)
                {
                    if (active.Music != null)
                    {
                        active.Music.stop();
                    }
                    Config.Spectating    = false;
                    Config.SpectatedUser = "";
                    Config.Specs         = "";
                    Game.setScreen(game.screens["menuScreen"]);
                }
                break;

            case (short)Pulse.Client.RecvHeaders.SPECTATE_USERS:
                Config.Specs = (string)arg2.info[0];
                Console.WriteLine(arg2.info[0]);
                break;

            case (short)Pulse.Client.RecvHeaders.SPECTATE_USERS_ME:
                Config.SpecsOnMe = (string)arg2.info[0];
                Console.WriteLine(arg2.info[0]);
                break;
            }
        }
Пример #5
0
 private void recPacket(short arg1, RecievePacket packet)
 {
     switch ((RecvHeaders)arg1)
     {
         case RecvHeaders.SPECTATE_HIT:
             int off = (int)packet.info[0];
             int diff = (int)packet.info[1];
             int lane = (int)packet.info[2];
             Replay.HitType t = (Replay.HitType)packet.info[3];
             hitTimingsToAdd.Add(new ReplayHit(off, diff, lane, t));
             break;
         case RecvHeaders.SPECTATE_PRESS:
             int off2 = (int)packet.info[0];
             int lane2 = (int)packet.info[1];
             pressTimingsToAdd.Add(new Pair<int, Pair<int, bool>>(off2, new Pair<int, bool>(lane2, false)));
             break;
         case RecvHeaders.SPECTATE_RELEASE:
             int off3 = (int)packet.info[0];
             int lane3 = (int)packet.info[1];
             releaseTimingsToAdd.Add(new Pair<int, Pair<int, bool>>(off3, new Pair<int, bool>(lane3, false)));
             break;
         case RecvHeaders.SPECTATE_HEARTBEAT:
             int off4 = (int)packet.info[0];
             int score = (int)packet.info[1];
             int combo = (int)packet.info[2];
             int hp = (int)packet.info[3];
             float accu = (float)((double)packet.info[4]);
             if (updateTime == -1234)
             {
                 scoreUpdate = score;
                 comboUpdate = combo;
                 updateTime = off4;
                 hpUpdate = hp;
                 accUpdate = accu;
             }
             if (first)
             {
                 running = true;
                 unpause();
                 music.PositionAsMilli = off4;
                 currentOffset = music.PositionAsMilli;
                 this.score.TotalScore = score;
                 this.score.Combo = combo;
                 this.hp = hp;
                 this.score.Accuracy = accu;
                 foreach (Note n in chart.Notes)
                 {
                     if (n.Offset < off4)
                     {
                         n.Enabled = false;
                     }
                 }
                 first = false;
             }
             bufferOffset = off4;
             if (buffering)
             {
                 if (bufferOffset - currentOffset > bufferAmount)
                 {
                     buffering = false;
                     unpause();
                 }
             }
             break;
         case RecvHeaders.SPECTATE_FINISH:
             //set score
             int sc = (int)packet.info[0];
             int co = (int)packet.info[1];
             int pr = (int)packet.info[2];
             int gr = (int)packet.info[3];
             int ok = (int)packet.info[4];
             int ms = (int)packet.info[5];
             int flags = (int)packet.info[6];
             float acc = (float)((double)packet.info[7]);
             bufferGap = 0;
             bufferOffset = endOffset + 2000;
             this.finalScore.TotalScore = sc;
             this.finalScore.Combo = co;
             this.finalScore.Perfects = pr;
             this.finalScore.Goods = gr;
             this.finalScore.Oks = ok;
             this.finalScore.Misses = ms;
             this.finalScore.Accuracy = acc;
             break;
         case RecvHeaders.SPECTATE_FAIL:
             bufferGap = 0;
             bufferOffset = endOffset + 2000;
             specFailed = true;
             break;
     }
 }