Exemplo n.º 1
0
 public void addplayerv1(playerinfor pi)
 {
     foreach (var v in players)
     {
         LoginServerProxy lsp;
         MatchServer.getsingleton().LoginServers.TryGetValue(pi.loginserverproxyid, out lsp);
         MemoryStream ms = new MemoryStream();
         Serializer.Serialize(ms, v.Value);
         byte[] btms    = ms.ToArray();
         byte[] t       = new byte[btms.Length + 4];
         byte[] ownerid = BitConverter.GetBytes(pi.playerid);
         Array.Copy(ownerid, 0, t, 0, 4);
         Array.Copy(btms, 0, t, 4, btms.Length);
         lsp.sendtologinserver((Byte)CMDMatchServer.OTHERPLAYERINFOR, t);
     }
     foreach (var v in players)
     {
         LoginServerProxy lsp;
         MatchServer.getsingleton().LoginServers.TryGetValue(v.Value.loginserverproxyid, out lsp);
         MemoryStream ms = new MemoryStream();
         Serializer.Serialize(ms, pi);
         byte[] btms    = ms.ToArray();
         byte[] t       = new byte[btms.Length + 4];
         byte[] ownerid = BitConverter.GetBytes(v.Value.playerid);
         Array.Copy(ownerid, 0, t, 0, 4);
         Array.Copy(btms, 0, t, 4, btms.Length);
         lsp.sendtologinserver((Byte)CMDMatchServer.OTHERPLAYERINFOR, t);
     }
     players.TryAdd(pi.playerid, pi);
     Logger.log("roomid : " + id + " number of players :" + players.Count);
     //if (players.Count == halfroomnumber)
     //{
     //}
 }
Exemplo n.º 2
0
        public void startgame()
        {
            int newid;

            if (RoomManager.getsingleton().creatingtocreated(id, out newid))
            {
                MatchServer.getsingleton().sendtoloadbalanceserver((byte)CMDLoadBalanceServer.CREATEDSV1, BitConverter.GetBytes(newid));
                Logger.log("startgame() create room =================================================== newid : " + newid + " id :" + id);
            }
        }
Exemplo n.º 3
0
        public RoomManager()
        {
            waitingRooms  = new ConcurrentDictionary <int, Room>();
            fightingRooms = new ConcurrentDictionary <int, Room>();

            CreatingRooms = new ConcurrentDictionary <int, Room>();
            CreatedRooms  = new ConcurrentDictionary <int, Room>();
            Task.Run(async() =>
            {
                try
                {
                    while (true)
                    {
                        await Task.Delay(1000);
                        foreach (var v in fightingRooms)
                        {
                            int number = v.Value.NumberOfOnlinePlayers();
                            if (number == 0)
                            {
                                MatchServer.getsingleton().sendtoloadbalanceserver((byte)CMDLoadBalanceServer.DESTROY, BitConverter.GetBytes(v.Key));
                                Room room;
                                fightingRooms.TryRemove(v.Key, out room);
                            }
                        }
                        //////////////////////////////////////////////////////////////////////////////
                        foreach (var v in CreatedRooms)
                        {
                            int number = v.Value.NumberOfOnlinePlayers();
                            if (number == 0)
                            {
                                MatchServer.getsingleton().sendtoloadbalanceserver((byte)CMDLoadBalanceServer.DESTROYV1, BitConverter.GetBytes(v.Key));
                                Room room;
                                CreatedRooms.TryRemove(v.Key, out room);
                                Logger.log("matchserver tell loadbalance destory a room");
                            }
                        }
                        foreach (var v in CreatingRooms)
                        {
                            int number = v.Value.NumberOfOnlinePlayers();
                            if (number == 0)
                            {
                                Room room;
                                CreatingRooms.TryRemove(v.Key, out room);
                            }
                        }
                    }
                }
                catch (Exception e)
                {
                    Logger.log(e.ToString());
                }
            });
        }
Exemplo n.º 4
0
 public void rejoin(playerinfor pi)
 {
     foreach (var v in players)
     {
         if (v.Value.offline)
         {
             continue;
         }
         LoginServerProxy lsp;
         MatchServer.getsingleton().LoginServers.TryGetValue(pi.loginserverproxyid, out lsp);
         MemoryStream ms = new MemoryStream();
         Serializer.Serialize(ms, v.Value);
         byte[] btms    = ms.ToArray();
         byte[] t       = new byte[btms.Length + 4];
         byte[] ownerid = BitConverter.GetBytes(pi.playerid);
         Array.Copy(ownerid, 0, t, 0, 4);
         Array.Copy(btms, 0, t, 4, btms.Length);
         lsp.sendtologinserver((Byte)CMDMatchServer.OTHERPLAYERINFOR, t);
     }
     foreach (var v in players)
     {
         if (v.Value.offline)
         {
             continue;
         }
         LoginServerProxy lsp;
         MatchServer.getsingleton().LoginServers.TryGetValue(v.Value.loginserverproxyid, out lsp);
         MemoryStream ms = new MemoryStream();
         Serializer.Serialize(ms, pi);
         byte[] btms    = ms.ToArray();
         byte[] t       = new byte[btms.Length + 4];
         byte[] ownerid = BitConverter.GetBytes(v.Value.playerid);
         Array.Copy(ownerid, 0, t, 0, 4);
         Array.Copy(btms, 0, t, 4, btms.Length);
         lsp.sendtologinserver((Byte)CMDMatchServer.OTHERPLAYERINFOR, t);
     }
     players.TryAdd(pi.playerid, pi);
 }
Exemplo n.º 5
0
        public void addplayer(playerinfor pi)
        {
            foreach (var v in players)
            {
                if (v.Value.offline)
                {
                    continue;
                }
                LoginServerProxy lsp;
                MatchServer.getsingleton().LoginServers.TryGetValue(pi.loginserverproxyid, out lsp);
                MemoryStream ms = new MemoryStream();
                Serializer.Serialize(ms, v.Value);
                byte[] btms    = ms.ToArray();
                byte[] t       = new byte[btms.Length + 4];
                byte[] ownerid = BitConverter.GetBytes(pi.playerid);
                Array.Copy(ownerid, 0, t, 0, 4);
                Array.Copy(btms, 0, t, 4, btms.Length);
                lsp.sendtologinserver((Byte)CMDMatchServer.OTHERPLAYERINFOR, t);
            }
            foreach (var v in players)
            {
                if (v.Value.offline)
                {
                    continue;
                }
                LoginServerProxy lsp;
                MatchServer.getsingleton().LoginServers.TryGetValue(v.Value.loginserverproxyid, out lsp);
                MemoryStream ms = new MemoryStream();
                Serializer.Serialize(ms, pi);
                byte[] btms    = ms.ToArray();
                byte[] t       = new byte[btms.Length + 4];
                byte[] ownerid = BitConverter.GetBytes(v.Value.playerid);
                Array.Copy(ownerid, 0, t, 0, 4);
                Array.Copy(btms, 0, t, 4, btms.Length);
                lsp.sendtologinserver((Byte)CMDMatchServer.OTHERPLAYERINFOR, t);
            }
////////////////////
            if (players.Count >= halfroomnumber)
            {
                pi.side = 1;
            }
            else
            {
                pi.side = 0;
            }
            players.TryAdd(pi.playerid, pi);
            if (players.Count == halfroomnumber)
            {
                b_wholeteam = true;
            }
            else
            {
                b_wholeteam = false;
            }
            if (players.Count == halfroomnumber * 2)
            {
                isfull = true;
                lock (RoomsLock)
                {
                    if (!b_created)
                    {
                        b_created = true;
                        Logger.log("room is full so create ds request=================================================== : " + id);
                        RoomManager.getsingleton().waitingtofighting(id);
                        MatchServer.getsingleton().sendtoloadbalanceserver((byte)CMDLoadBalanceServer.CREATEDS, BitConverter.GetBytes(id));
                    }
                }
            }
            Task.Run(async() =>
            {
                try
                {
                    await Task.Delay(System.TimeSpan.FromMilliseconds(Room.expiredtime));
                    Logger.log("room time expired 000");
                    b_anyplayerisok = true;
                    /////////////////////////////////////////////////////////////////////////
                    ///
                    await Task.Delay(System.TimeSpan.FromMilliseconds(Room.expiredtime));
                    lock (RoomsLock)
                    {
                        if (!b_created)
                        {
                            b_created = true;
                            Logger.log("room time expired 111===============================================================: " + id);
                            RoomManager.getsingleton().waitingtofighting(id);
                            MatchServer.getsingleton().sendtoloadbalanceserver((byte)CMDLoadBalanceServer.CREATEDS, BitConverter.GetBytes(id));
                        }
                    }
                }
                catch (Exception e)
                {
                    Logger.log(e.ToString());
                }
            });
        }