Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent ignored users from joining games #651

Open
wants to merge 13 commits into
base: develop
Choose a base branch
from
26 changes: 24 additions & 2 deletions DXMainClient/DXGUI/Multiplayer/GameLobby/CnCNetGameLobby.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
using System.Text;
using DTAClient.Domain.Multiplayer.CnCNet;
using ClientCore.Extensions;
using System.Net.NetworkInformation;

namespace DTAClient.DXGUI.Multiplayer.GameLobby
{
Expand Down Expand Up @@ -521,6 +522,15 @@ private void Channel_UserListReceived(object sender, EventArgs e)
private void Channel_UserAdded(object sender, ChannelUserEventArgs e)
{
PlayerInfo pInfo = new PlayerInfo(e.User.IRCUser.Name);

if (IsHost && e.User.IRCUser.IsIgnored)
{
// If this ignored player constantly rejoins, he could cause the host to floodout using the normal RemovePlayer() functionality.
// So lets Ghost kickban from gameroom instead. This should only be needed once per created room
GhostBanIgnoredUser(pInfo.Name);
return;
}

Players.Add(pInfo);

if (Players.Count + AIPlayers.Count > MAX_PLAYER_COUNT && AIPlayers.Count > 0)
Expand Down Expand Up @@ -1553,8 +1563,20 @@ protected override void BanPlayer(int playerIndex)
if (user != null)
{
AddNotice(string.Format("Banning and kicking {0} from the game...".L10N("Client:Main:BanAndKickPlayer"), pInfo.Name));
channel.SendBanMessage(user.Hostname, 8);
channel.SendKickMessage(user.Name, 8);
channel.SendBanMessage(user.Hostname, priority: 8);
channel.SendKickMessage(user.Name, priority: 8);
}
}

private void GhostBanIgnoredUser(string playerName)
{
var user = connectionManager.UserList.Find(u => u.Name == playerName);
SadPencil marked this conversation as resolved.
Show resolved Hide resolved

if (user != null)
{
// Informing the host like we do when we kick might be annoying. So keep it on the downlow.
channel.SendBanMessage(user.Hostname, priority: 8);
channel.SendKickMessage(user.Name, priority: 8);
}
}

Expand Down
11 changes: 6 additions & 5 deletions DXMainClient/Online/Channel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,11 +112,11 @@ public void AddUser(ChannelUser user)
UserAdded?.Invoke(this, new ChannelUserEventArgs(user));
}

public void OnUserJoined(ChannelUser user)
public void OnUserJoined(ChannelUser user, bool isSilent = false)
{
AddUser(user);

if (notifyOnUserListChange)
if (notifyOnUserListChange && !isSilent)
{
AddMessage(new ChatMessage(
string.Format("{0} has joined {1}.".L10N("Client:Main:PlayerJoinChannel"), user.IRCUser.Name, UIName)));
Expand Down Expand Up @@ -152,7 +152,7 @@ public void OnUserListReceived(List<ChannelUser> userList)
UserListReceived?.Invoke(this, EventArgs.Empty);
}

public void OnUserKicked(string userName)
public void OnUserKicked(string userName, bool isSilent = false)
{
if (users.Remove(userName))
{
Expand All @@ -161,8 +161,9 @@ public void OnUserKicked(string userName)
users.Clear();
}

AddMessage(new ChatMessage(
string.Format("{0} has been kicked from {1}.".L10N("Client:Main:PlayerKickedFromChannel"), userName, UIName)));
if (!isSilent)
AddMessage(new ChatMessage(
string.Format("{0} has been kicked from {1}.".L10N("Client:Main:PlayerKickedFromChannel"), userName, UIName)));

UserKicked?.Invoke(this, new UserNameEventArgs(userName));
}
Expand Down
15 changes: 13 additions & 2 deletions DXMainClient/Online/CnCNetManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,8 @@ public bool IsAttemptingConnection

private bool disconnect = false;

private bool userListInitialized = false;

public bool IsCnCNetInitialized()
{
return Connection.IsIdSet();
Expand Down Expand Up @@ -500,6 +502,7 @@ private void DoDisconnected()

MainChannel.AddMessage(new ChatMessage("You have disconnected from CnCNet.".L10N("Client:Main:CncNetDisconnected")));
connected = false;
userListInitialized = false;

UserList.Clear();

Expand Down Expand Up @@ -620,7 +623,7 @@ private void DoUserJoinedChannel(string channelName, string host, string userNam
channelUser.IsFriend = cncNetUserData.IsFriend(channelUser.IRCUser.Name);

ircUser.Channels.Add(channelName);
channel.OnUserJoined(channelUser);
channel.OnUserJoined(channelUser, isSilent: channelUser.IRCUser.IsIgnored);

//UserJoinedChannel?.Invoke(this, new ChannelUserEventArgs(channelName, userName));
}
Expand All @@ -645,7 +648,8 @@ private void DoUserKicked(string channelName, string userName)
if (channel == null)
return;

channel.OnUserKicked(userName);
ChannelUser kickedUser = channel.Users.Find(userName);
channel.OnUserKicked(userName, isSilent: kickedUser.IRCUser.IsIgnored);

if (userName == ProgramConstants.PLAYERNAME)
{
Expand Down Expand Up @@ -770,6 +774,13 @@ private void DoUserListReceived(string channelName, string[] userList)
MultipleUsersAdded?.Invoke(this, EventArgs.Empty);

channel.OnUserListReceived(channelUserList);

// We only need to request user info once, and chat channels only.
SadPencil marked this conversation as resolved.
Show resolved Hide resolved
if (!userListInitialized && channel.IsChatChannel)
{
channel.RequestUserInfo();
userListInitialized = true;
}
}

public void OnUserQuitIRC(string userName)
Expand Down
Loading