Ejemplo n.º 1
0
        private async Task Process(JoinBattleSuccess bat)
        {
            Battle battle;

            ExistingBattles.TryGetValue(bat.BattleID, out battle);
            if (battle != null)
            {
                battle.Users.Clear();
                foreach (var battleStatusUpdate in bat.Players)
                {
                    var ubs = new UserBattleStatus(battleStatusUpdate.Name, ExistingUsers.Get(battleStatusUpdate.Name));
                    ubs.UpdateWith(battleStatusUpdate);
                    battle.Users[battleStatusUpdate.Name] = ubs;
                }

                battle.Bots.Clear();
                foreach (var botStatusUpdate in bat.Bots)
                {
                    var ubs = new BotBattleStatus(botStatusUpdate.Name, botStatusUpdate.Owner, botStatusUpdate.AiLib);
                    ubs.UpdateWith(botStatusUpdate);
                    battle.Bots[botStatusUpdate.Name] = ubs;
                    BattleBotAdded(this, ubs);
                }

                MyBattle = battle;
                if (battle.FounderName == UserName)
                {
                    BattleOpened(this, battle);
                }
                BattleJoinSuccess(this, MyBattle);
            }
        }
Ejemplo n.º 2
0
        void OnRemoveUser(string[] args)
        {
            var userName = args[0];

            //var user = ExistingUsers[userName];   // unused; just gives KeyNotFound exceptions
            UserRemoved(this, new TasEventArgs(args));
            ExistingUsers.Remove(userName);
        }
Ejemplo n.º 3
0
 void OnAddUser(string[] args)
 {
     try {
         var u = User.Create(args[0]);
         u.Country = args[1];
         int cpu;
         int.TryParse(args[2], out cpu);
         u.Cpu     = cpu;
         u.LobbyID = Convert.ToInt32(args[3]);
         ExistingUsers.Add(u.Name, u);
         UserAdded(this, new EventArgs <User>(u));
     } catch (Exception e) {
         //TraceError ensure bright red coloured message (WriteLine looked harmless):
         Trace.TraceError("Error was thrown while processing chat command ADDUSER (check if this event trigger faulty code in application): " + e);
     }
 }
Ejemplo n.º 4
0
        private async Task Process(JoinChannelResponse response)
        {
            if (response.Success)
            {
                var chan = new Channel()
                {
                    Name = response.Channel.ChannelName, Topic = response.Channel.Topic,
                };

                JoinedChannels[response.ChannelName] = chan;

                foreach (var u in response.Channel.Users)
                {
                    User user;
                    if (ExistingUsers.TryGetValue(u, out user))
                    {
                        chan.Users[u] = user;
                    }
                }

                var cancelEvent = new CancelEventArgs <Channel>(chan);
                PreviewChannelJoined(this, cancelEvent);
                if (!cancelEvent.Cancel)
                {
                    ChannelJoined(this, chan);
                    ChannelUserAdded(this, new ChannelUserInfo()
                    {
                        Channel = chan, Users = chan.Users.Values.ToList()
                    });
                    if (!string.IsNullOrEmpty(chan.Topic.Text))
                    {
                        ChannelTopicChanged(this, new ChangeTopic()
                        {
                            ChannelName = chan.Name, Topic = chan.Topic
                        });
                    }
                }
            }
            else
            {
                ChannelJoinFailed(this, response);
            }
        }
Ejemplo n.º 5
0
        public TasClient(string appName, Login.ClientTypes?clientTypes = null, string ipOverride = null)
        {
            if (clientTypes.HasValue)
            {
                this.clientType = clientTypes.Value;
            }
            this.appName = appName;


            if (!string.IsNullOrEmpty(ipOverride))
            {
                localIp       = ipOverride;
                forcedLocalIP = true;
            }
            else
            {
                var addresses = Dns.GetHostAddresses(Dns.GetHostName());

                localIp = addresses[0].ToString();
                foreach (var adr in addresses)
                {
                    if (adr.AddressFamily == AddressFamily.InterNetwork)
                    {
                        localIp = adr.ToString();
                        break;
                    }
                }
            }

            Extensions = new ProtocolExtension(this, (user, data) => {
                User u;
                if (ExistingUsers.TryGetValue(user, out u))
                {
                    UserExtensionsChanged(this, new EventArgs <User>(u));
                }
            });

            pingTimer = new Timer(pingInterval * 1000)
            {
                AutoReset = true
            };
            pingTimer.Elapsed += OnPingTimer;
        }
Ejemplo n.º 6
0
        public ActionResult AllExistingUsers()
        {
            List <ExistingUsers> CurrentUsers = new List <ExistingUsers>();

            try
            {
                if (ModelState.IsValid)
                {
                    var allUsersNeeded = from usertable in database.DX_USER where usertable.accesslevel != Constants.TEMP_USER_ACCESS && usertable.accesslevel != Constants.ADMIN_USER_ACCESS && usertable.accesslevel != Constants.ADMINLESS_USER_ACCESS select usertable;

                    if (allUsersNeeded != null && allUsersNeeded.ToList().Count >= 1)
                    {
                        List <DX_USER> users = (List <DX_USER>)allUsersNeeded.ToList();

                        foreach (DX_USER presentuser in users)
                        {
                            ExistingUsers CurrentExistingUser = new ExistingUsers();
                            CurrentExistingUser.Email       = presentuser.userid;
                            CurrentExistingUser.Name        = presentuser.fname + " " + presentuser.lname;
                            CurrentExistingUser.Position    = presentuser.role;
                            CurrentExistingUser.accessLevel = presentuser.accesslevel;
                            List <string> depts      = DbCommonQueries.getDepartmentName(presentuser.userid, database);
                            string        department = "";
                            foreach (string dept in depts)
                            {
                                department = department + dept + ", ";
                            }
                            ;
                            CurrentExistingUser.Department   = department;
                            CurrentExistingUser.creationDate = new DateTime();
                            CurrentUsers.Add(CurrentExistingUser);
                        }
                    }
                }
            }
            catch { ModelState.AddModelError("", "Error occured while populating existing users"); }
            return(View(CurrentUsers));
        }
Ejemplo n.º 7
0
        private async Task Process(ChannelUserAdded arg)
        {
            Channel chan;

            if (JoinedChannels.TryGetValue(arg.ChannelName, out chan))
            {
                if (!chan.Users.ContainsKey(arg.UserName))
                {
                    User user;
                    if (ExistingUsers.TryGetValue(arg.UserName, out user))
                    {
                        chan.Users[arg.UserName] = user;
                        ChannelUserAdded(this, new ChannelUserInfo()
                        {
                            Channel = chan, Users = new List <User>()
                            {
                                user
                            }
                        });
                    }
                }
            }
        }
Ejemplo n.º 8
0
        private async Task Process(User userUpdate)
        {
            User user;
            User old = null;

            ExistingUsers.TryGetValue(userUpdate.Name, out user);
            if (user != null)
            {
                old = user.Clone();
                user.UpdateWith(userUpdate);
            }
            else
            {
                user = userUpdate;
            }
            ExistingUsers[user.Name] = user;

            if (old == null)
            {
                UserAdded(this, user);
                await Process(new ChannelUserAdded()
                {
                    UserName = user.Name, ChannelName = "zk"
                });                                                                                 // silly hacky thing to make all Users appear in #zk remove later
            }
            var battleID    = user.BattleID;
            var oldBattleID = old?.BattleID;

            if (battleID != oldBattleID)
            {
                if (battleID.HasValue)
                {
                    ExistingBattles.Get(battleID.Value)?.Users.TryAdd(user.Name, new UserBattleStatus(user.Name, user));
                    BattleUserJoined(this, new BattleUserEventArgs(user.Name, battleID.Value));
                }
                else
                {
                    UserBattleStatus oldu;
                    var obat = ExistingBattles.Get(oldBattleID ?? 0);
                    obat?.Users.TryRemove(user.Name, out oldu);
                    BattleUserLeft(this, new BattleUserEventArgs(user.Name, oldBattleID ?? 0));
                    if (user.Name == UserName)
                    {
                        MyBattle = null;
                        BattleClosed(this, obat);
                    }
                }
            }

            var bat = MyBattle;

            if ((bat != null) && (bat.FounderName == user.Name))
            {
                if (!user.IsInGame && old?.IsInGame == true)
                {
                    MyBattleHostExited(this, bat);
                }
            }

            if (user.Name == UserName)
            {
                MyUserStatusChanged(this, new OldNewPair <User>(old, user));
            }
            UserStatusChanged(this, new OldNewPair <User>(old, user));
        }
Ejemplo n.º 9
0
 public bool GetExistingUser(string name, out User u)
 {
     return(ExistingUsers.TryGetValue(name, out u));
 }
Ejemplo n.º 10
0
 private async Task Process(UserDisconnected arg)
 {
     ExistingUsers.Remove(arg.Name);
     UserRemoved(this, arg);
 }
Ejemplo n.º 11
0
        User UserGetter(string n)
        {
            User us;

            if (existingUsers.TryGetValue(n, out us))
            {
                return(us);
            }
            else
            {
                return new User()
                       {
                           Name = n
                       }
            };
        }

        async Task Process(BattleAdded bat)
        {
            var newBattle = new Battle();

            newBattle.UpdateWith(bat.Header, UserGetter);
            existingBattles[newBattle.BattleID] = newBattle;
            newBattle.Founder.IsInBattleRoom    = true;

            BattleFound(this, new EventArgs <Battle>(newBattle));
        }

        async Task Process(JoinedBattle bat)
        {
            User user;

            existingUsers.TryGetValue(bat.User, out user);
            Battle battle;

            ExistingBattles.TryGetValue(bat.BattleID, out battle);
            if (user != null && battle != null)
            {
                battle.Users[user.Name] = new UserBattleStatus(user.Name, user);

                user.IsInBattleRoom = true;
                BattleUserJoined(this, new BattleUserEventArgs(user.Name, bat.BattleID));
                if (user.Name == UserName)
                {
                    MyBattle = battle;
                    if (battle.Founder.Name == UserName)
                    {
                        BattleOpened(this, new EventArgs <Battle>(battle));
                    }
                    BattleJoined(this, new EventArgs <Battle>(MyBattle));
                }
            }
        }

        async Task Process(LeftBattle left)
        {
            User   user;
            Battle bat;

            existingUsers.TryGetValue(left.User, out user);
            existingBattles.TryGetValue(left.BattleID, out bat);

            if (bat != null && user != null)
            {
                user.IsInBattleRoom = false;
                UserBattleStatus removed;
                bat.Users.TryRemove(left.User, out removed);

                if (MyBattle != null && left.BattleID == MyBattleID)
                {
                    if (UserName == left.User)
                    {
                        bat.Rectangles.Clear();
                        bat.Bots.Clear();
                        bat.ModOptions.Clear();
                        MyBattle = null;
                        BattleClosed(this, new EventArgs <Battle>(bat));
                    }
                }
                BattleUserLeft(this, new BattleUserEventArgs(user.Name, left.BattleID));
            }
        }

        async Task Process(BattleRemoved br)
        {
            Battle battle;

            if (!existingBattles.TryGetValue(br.BattleID, out battle))
            {
                return;
            }
            foreach (var u in battle.Users.Keys)
            {
                User user;
                if (ExistingUsers.TryGetValue(u, out user))
                {
                    user.IsInBattleRoom = false;
                }
            }

            existingBattles.Remove(br.BattleID);
            if (battle == MyBattle)
            {
                BattleClosed(this, new EventArgs <Battle>(battle));
                MyBattleRemoved(this, new EventArgs <Battle>(battle));
            }
            BattleRemoved(this, new EventArgs <Battle>(battle));
        }

        async Task Process(LoginResponse loginResponse)
        {
            if (loginResponse.ResultCode == LoginResponse.Code.Ok)
            {
                isLoggedIn = true;
                LoginAccepted(this, new TasEventArgs());
            }
            else
            {
                isLoggedIn = false;
                LoginDenied(this, new EventArgs <LoginResponse>(loginResponse));
            }
        }

        async Task Process(Ping ping)
        {
            lastPing = DateTime.UtcNow;
        }

        async Task Process(User userUpdate)
        {
            User user;
            User old = null;

            existingUsers.TryGetValue(userUpdate.Name, out user);
            if (user != null)
            {
                old = user.Clone();
                user.UpdateWith(userUpdate);
            }
            else
            {
                user = userUpdate;
            }
            existingUsers[user.Name] = user;

            if (old == null)
            {
                UserAdded(this, new EventArgs <User>(user));
            }
            if (old != null)
            {
                var bat = MyBattle;
                if (bat != null && bat.Founder.Name == user.Name)
                {
                    if (user.IsInGame && !old.IsInGame)
                    {
                        MyBattleStarted(this, new EventArgs <Battle>(bat));
                    }
                    if (!user.IsInGame && old.IsInGame)
                    {
                        MyBattleHostExited(this, new EventArgs <Battle>(bat));
                    }
                }
            }
            UserStatusChanged(this, new EventArgs <OldNewPair <User> >(new OldNewPair <User>(old, user)));
        }

        async Task Process(RegisterResponse registerResponse)
        {
            if (registerResponse.ResultCode == RegisterResponse.Code.Ok)
            {
                RegistrationAccepted(this, new TasEventArgs());
            }
            else
            {
                RegistrationDenied(this, new EventArgs <RegisterResponse>(registerResponse));
            }
        }

        async Task Process(Say say)
        {
            InvokeSaid(new TasSayEventArgs(say.Place, say.Target, say.User, say.Text, say.IsEmote));
            if (say.Ring)
            {
                Rang(this, new EventArgs <Say>(say));
            }
        }