public async Task Process(Login login) { var ret = await Task.Run(() => server.LoginChecker.DoLogin(login, RemoteEndpointIP, login.Dlc)); if (ret.LoginResponse.ResultCode == LoginResponse.Code.Ok) { var user = ret.User; //Trace.TraceInformation("{0} login: {1}", this, response.ResultCode.Description()); await this.SendCommand(user); // send self to self first connectedUser = server.ConnectedUsers.GetOrAdd(user.Name, (n) => new ConnectedUser(server, user)); connectedUser.User = user; connectedUser.Connections.TryAdd(this, true); // close other connections foreach (var otherConnection in connectedUser.Connections.Keys.Where(x => x != null && x != this).ToList()) { otherConnection.RequestClose(); bool oth; connectedUser.Connections.TryRemove(otherConnection, out oth); } server.SessionTokens[ret.LoginResponse.SessionToken] = user.AccountID; await SendCommand(ret.LoginResponse); // login accepted connectedUser.ResetHasSeen(); foreach (var b in server.Battles.Values.Where(x => x != null)) { await SendCommand(new BattleAdded() { Header = b.GetHeader() }); } // mutually syncs users based on visibility rules await server.TwoWaySyncUsers(Name, server.ConnectedUsers.Keys); server.OfflineMessageHandler.SendMissedMessagesAsync(this, SayPlace.User, Name, user.AccountID); var defChans = await server.ChannelManager.GetDefaultChannels(user.AccountID); defChans.AddRange(server.Channels.Where(x => x.Value.Users.ContainsKey(user.Name)).Select(x => x.Key)); // add currently connected channels to list too foreach (var chan in defChans.ToList().Distinct()) { await connectedUser.Process(new JoinChannel() { ChannelName = chan, Password = null }); } foreach (var bat in server.Battles.Values.Where(x => x != null && x.IsInGame)) { var s = bat.spring; if (s.LobbyStartContext.Players.Any(x => !x.IsSpectator && x.Name == Name) && !s.Context.ActualPlayers.Any(x => x.Name == Name && x.LoseTime != null)) { await SendCommand(new RejoinOption() { BattleID = bat.BattleID }); } } await SendCommand(new FriendList() { Friends = connectedUser.FriendEntries.ToList() }); await SendCommand(new IgnoreList() { Ignores = connectedUser.Ignores.ToList() }); await server.MatchMaker.OnLoginAccepted(connectedUser); await server.PlanetWarsMatchMaker.OnLoginAccepted(connectedUser); await SendCommand(server.NewsListManager.GetCurrentNewsList()); await SendCommand(server.LadderListManager.GetCurrentLadderList()); await SendCommand(server.ForumListManager.GetCurrentForumList(user.AccountID)); using (var db = new ZkDataContext()) { var acc = db.Accounts.Find(user.AccountID); if (acc != null) { await server.PublishUserProfileUpdate(acc); } } } else { await SendCommand(ret.LoginResponse); if (ret.LoginResponse.ResultCode == LoginResponse.Code.Banned) { await Task.Delay(500); // this is needed because socket writes are async and might not be queued yet await transport.Flush(); transport.RequestClose(); } } }
public async Task Process(Login login) { var ret = await Task.Run(() => server.LoginChecker.DoLogin(login, RemoteEndpointIP)); if (ret.LoginResponse.ResultCode == LoginResponse.Code.Ok) { var user = ret.User; //Trace.TraceInformation("{0} login: {1}", this, response.ResultCode.Description()); await this.SendCommand(user); // send self to self first connectedUser = server.ConnectedUsers.GetOrAdd(user.Name, (n) => new ConnectedUser(server, user)); connectedUser.User = user; connectedUser.Connections.TryAdd(this, true); server.SessionTokens[ret.LoginResponse.SessionToken] = user.AccountID; await SendCommand(ret.LoginResponse); // login accepted connectedUser.ResetHasSeen(); foreach (var b in server.Battles.Values.Where(x => x != null)) { await SendCommand(new BattleAdded() { Header = b.GetHeader() }); } // mutually syncs users based on visibility rules await server.TwoWaySyncUsers(Name, server.ConnectedUsers.Keys); server.OfflineMessageHandler.SendMissedMessagesAsync(this, SayPlace.User, Name, user.AccountID); var defChans = await server.ChannelManager.GetDefaultChannels(user.AccountID); defChans.AddRange(server.Channels.Where(x => x.Value.Users.ContainsKey(user.Name)).Select(x => x.Key)); // add currently connected channels to list too foreach (var chan in defChans.ToList().Distinct()) { await connectedUser.Process(new JoinChannel() { ChannelName = chan, Password = null }); } foreach (var bat in server.Battles.Values.Where(x => x != null && x.IsInGame)) { var s = bat.spring; if (s.LobbyStartContext.Players.Any(x => !x.IsSpectator && x.Name == Name) && !s.Context.ActualPlayers.Any(x => x.Name == Name && x.LoseTime != null)) { await SendCommand(new RejoinOption() { BattleID = bat.BattleID }); } } await SendCommand(new FriendList() { Friends = connectedUser.FriendEntries.ToList() }); await SendCommand(new IgnoreList() { Ignores = connectedUser.Ignores.ToList() }); await server.MatchMaker.OnLoginAccepted(connectedUser); await server.PlanetWarsMatchMaker.OnLoginAccepted(connectedUser); } else { await SendCommand(ret.LoginResponse); if (ret.LoginResponse.ResultCode == LoginResponse.Code.Banned) { transport.RequestClose(); } } }