[C#] Disconnecting a spacific player

05/07/2016 17:35 Kardil#1
Hello elites,
as title says i wanna disconnect a spacific player how should i do that?
05/07/2016 18:31 AceSpace#2
Well if it's a filter, try creating a list and add every player on it aka PlayersList.Add(this); etc
Then make a loop or use linq.

Like:
Code:
for (int i =0; i < PlayersList.Count; i++)
{
if (PlayersList[i].CharName == ""Kardil") //example
   PlayersList[i].Disconnect(); // call disconnect
}
or LINQ:
Code:
var Player = PlayersList.Where(p => p.CharName == "Kardil");
Player.Disconnect();
Though the list must be in a different class from the class which handles the player packets etc aka the base itself.
05/07/2016 19:23 Kardil#3
Thanks alot, iam really use a list but seems i couldn't be obvious enough
iam asking about that part

PHP Code:
PlayersList[i].Disconnect(); 
The Disconnect function itself, how it works? i heard that it working with a socket and i have it but it's disconnecting everyone in the server, i mean i can't determine just one player to let that socket work on him only.

hope iam obvious this time.
05/08/2016 12:59 AceSpace#4
Quote:
Originally Posted by Kardil View Post
Thanks alot, iam really use a list but seems i couldn't be obvious enough
iam asking about that part

PHP Code:
PlayersList[i].Disconnect(); 
The Disconnect function itself, how it works? i heard that it working with a socket and i have it but it's disconnecting everyone in the server, i mean i can't determine just one player to let that socket work on him only.

hope iam obvious this time.
Socket.Close();?
And you need to create a new instance for every new connection for it to have it's own socket.
05/09/2016 14:17 Kardil#5
Quote:
Originally Posted by Skipper* View Post
Socket.Close();?
And you need to create a new instance for every new connection for it to have it's own socket.
Yes that's exactly what am trying to say/to do but i don't have an idea how to do that
When i send that everyone disconnects not just the one i want

So any guide or good hint?
05/09/2016 17:49 sarkoplata#6
Quote:
Originally Posted by Kardil View Post
Yes that's exactly what am trying to say/to do but i don't have an idea how to do that
When i send that everyone disconnects not just the one i want

So any guide or good hint?
Find the player's instance's client socket and close it...
PlayersList[i].ClientSocket.Close();

it doesn't get any easier than that
05/10/2016 06:10 MeGaMaX#7
get his CharName > UserID > SMC > UserControl > put UserID press Query find his userid press ban xD ? or simply put his ip in windows firewall for a sec :D, im kidding btw xD.

//Get the player client socket and close it !
05/10/2016 06:21 AceSpace#8
Alright I made a fast project to see you how it works. I attached it below, open it with VS & see how it works.

Commands => /begin - will add players to list
/disconnect - will dc player based on number of player
/list - will list current online players
/count - will tell you the count of the online players

This couldn't be any easier..
05/12/2016 23:52 Kardil#9
I could do it, Thanks everyone here it's appreciated.
07/16/2016 16:05 PlayIGNITE#10
First you should make a loop and define i as integer and = 0 . as shown then use the if condition
for (int i =0; i < PlayersList.Count; i++)
{
if (PlayersList[i].CharName == ""Kardil") //example
PlayersList[i].Disconnect(); // call disconnect
}