C# Class MCSharp.Player

Show file Open project: Voziv/MCSharp Class Usage Examples

Public Properties

Property Type Description
Loading bool
bindings byte[]
connections List
disconnected bool
group Group
hidden bool
id byte
ip string
isJailed bool
isJoker bool
isMuted bool
lastSeen DateTime>.Dictionary
left string>.Dictionary
name string
players ThreadedBindingList

Public Methods

Method Description
Ban ( string name ) : void

Changes the players rank to banned.

ChangeRank ( Player p, GroupEnum g ) : void

Changes a players rank

ChangeRank ( string name, GroupEnum g ) : void

Changes the given players rank

Disconnect ( ) : void

Handles a player disconnection. Cleans up the player from other players on the server as well as handles cleaning up the player from the system.

Exists ( byte id ) : bool

Checks to see if a player exists in the list

Exists ( string name ) : bool

Checks to see if a player exists in the list

Find ( string name ) : Player

Finds a player in the list

GZip ( byte bytes ) : byte[]

Zips an array of bytes using gzip

GetColor ( string name ) : string

Gets the color for a given player

GetGroup ( string name ) : Group

Get the group of a given player

GetPlayers ( ) : List

Returns the list of players.

GetRank ( string name ) : GroupEnum

Gets a players rank

HandleBlockchange ( byte message ) : void

Handles a player blockchange packet

HandleLogin ( byte message ) : void

Handles a player login packet

IsOnline ( string name ) : bool

Determines if the user is online

Kick ( string message ) : void

Kicks the player with a given message

Player ( Socket s ) : System

The main constructor for the player.

SMPKick ( string message ) : void

A kick function that works for the new SMP clients. That way they have a friendly way of being removed from the server instead of "Invalid packet id 2"

SendBlockchange ( ushort x, ushort y, ushort z, byte type ) : void
SendChat ( Player p, string message ) : void
SendDie ( byte id ) : void
SendKick ( string message ) : void
SendMap ( ) : void
SendMessage ( byte id, string message ) : void
SendMessage ( string message ) : void
SendMotd ( ) : void
SendPing ( ) : void
SendPos ( byte id, ushort x, ushort y, ushort z, byte rotx, byte roty ) : void
SendRaw ( byte send ) : void
SendRaw ( int id ) : void
SendRaw ( int id, byte send ) : void
SendSpawn ( byte id, string name, ushort x, ushort y, ushort z, byte rotx, byte roty ) : void
ToString ( ) : string
UpdatePosition ( ) : void
ValidName ( string name ) : bool

Checks to see if a players name is valid

initNetworking ( Socket s ) : void

Initializes the players networking and handles the incoming socket connection.

loginTimerCallback ( Object sender, ElapsedEventArgs e ) : void

Handles the login timer callback once it finishes. If the player has not been authenticated then we kick them.

Private Methods

Method Description
CheckBlockSpam ( ) : bool

Detects whether or not a player is spamming blocks around the map

FreeId ( ) : byte

Find the next free id available

HTNO ( short x ) : byte[]

Converts a short to network byte order

HTNO ( ushort x ) : byte[]

Converts a ushort to network byte order

HandleMessage ( byte buffer ) : byte[]

Handles messages in the buffer

NTHO ( byte x, int offset ) : ushort

Converts a ushort to host byte order

Receive ( IAsyncResult result ) : void

Handles network callbacks and adding to the players buffer

StringFormat ( string str, int size ) : byte[]

Formats a string

Wordwrap ( string message ) : List

Performs wordwrap on a string

checkOp ( ) : bool

Checks to see if the player has operator permissions

Method Details

Ban() public static method

Changes the players rank to banned.
public static Ban ( string name ) : void
name string The player's name to ban
return void

ChangeRank() public static method

Changes a players rank
public static ChangeRank ( Player p, GroupEnum g ) : void
p Player The player object to change
g GroupEnum The rank to change the player to
return void

ChangeRank() public static method

Changes the given players rank
public static ChangeRank ( string name, GroupEnum g ) : void
name string The name of the player
g GroupEnum The players new rank
return void

Disconnect() public method

Handles a player disconnection. Cleans up the player from other players on the server as well as handles cleaning up the player from the system.
public Disconnect ( ) : void
return void

Exists() public static method

Checks to see if a player exists in the list
public static Exists ( byte id ) : bool
id byte The id of the player
return bool

Exists() public static method

Checks to see if a player exists in the list
public static Exists ( string name ) : bool
name string the players name
return bool

Find() public static method

Finds a player in the list
public static Find ( string name ) : Player
name string The name of the player
return Player

GZip() public static method

Zips an array of bytes using gzip
public static GZip ( byte bytes ) : byte[]
bytes byte The bytes to zip
return byte[]

GetColor() public static method

Gets the color for a given player
public static GetColor ( string name ) : string
name string The player to get the color for
return string

GetGroup() public static method

Get the group of a given player
public static GetGroup ( string name ) : Group
name string The players name
return Group

GetPlayers() public static method

Returns the list of players.
public static GetPlayers ( ) : List
return List

GetRank() public static method

Gets a players rank
public static GetRank ( string name ) : GroupEnum
name string The player name to get the rank for
return GroupEnum

HandleBlockchange() public method

Handles a player blockchange packet
public HandleBlockchange ( byte message ) : void
message byte The blockchange packet
return void

HandleLogin() public method

Handles a player login packet
public HandleLogin ( byte message ) : void
message byte The login packet
return void

IsOnline() public static method

Determines if the user is online
public static IsOnline ( string name ) : bool
name string The player's name
return bool

Kick() public method

Kicks the player with a given message
public Kick ( string message ) : void
message string The reason the player was kicked
return void

Player() public method

The main constructor for the player.
public Player ( Socket s ) : System
s Socket The incoming socket connection for the player to bind to
return System

SMPKick() public method

A kick function that works for the new SMP clients. That way they have a friendly way of being removed from the server instead of "Invalid packet id 2"
public SMPKick ( string message ) : void
message string The message to kick a SMP player with
return void

SendBlockchange() public method

public SendBlockchange ( ushort x, ushort y, ushort z, byte type ) : void
x ushort
y ushort
z ushort
type byte
return void

SendChat() public method

public SendChat ( Player p, string message ) : void
p Player
message string
return void

SendDie() public method

public SendDie ( byte id ) : void
id byte
return void

SendKick() public method

public SendKick ( string message ) : void
message string
return void

SendMap() public method

public SendMap ( ) : void
return void

SendMessage() public method

public SendMessage ( byte id, string message ) : void
id byte
message string
return void

SendMessage() public method

public SendMessage ( string message ) : void
message string
return void

SendMotd() public method

public SendMotd ( ) : void
return void

SendPing() public method

public SendPing ( ) : void
return void

SendPos() public method

public SendPos ( byte id, ushort x, ushort y, ushort z, byte rotx, byte roty ) : void
id byte
x ushort
y ushort
z ushort
rotx byte
roty byte
return void

SendRaw() public method

public SendRaw ( byte send ) : void
send byte
return void

SendRaw() public method

public SendRaw ( int id ) : void
id int
return void

SendRaw() public method

public SendRaw ( int id, byte send ) : void
id int
send byte
return void

SendSpawn() public method

public SendSpawn ( byte id, string name, ushort x, ushort y, ushort z, byte rotx, byte roty ) : void
id byte
name string
x ushort
y ushort
z ushort
rotx byte
roty byte
return void

ToString() public method

public ToString ( ) : string
return string

UpdatePosition() public method

public UpdatePosition ( ) : void
return void

ValidName() public static method

Checks to see if a players name is valid
public static ValidName ( string name ) : bool
name string
return bool

initNetworking() public method

Initializes the players networking and handles the incoming socket connection.
public initNetworking ( Socket s ) : void
s Socket The incoming socket connection
return void

loginTimerCallback() public method

Handles the login timer callback once it finishes. If the player has not been authenticated then we kick them.
public loginTimerCallback ( Object sender, ElapsedEventArgs e ) : void
sender Object
e ElapsedEventArgs
return void

Property Details

Loading public property

public bool Loading
return bool

bindings public property

public byte[] bindings
return byte[]

connections public static property

public static List connections
return List

disconnected public property

public bool disconnected
return bool

group public property

public Group group
return Group

hidden public property

public bool hidden
return bool

id public property

public byte id
return byte

ip public property

public string ip
return string

isJailed public property

public bool isJailed
return bool

isJoker public property

public bool isJoker
return bool

isMuted public property

public bool isMuted
return bool

lastSeen public static property

This keeps track of when a player was last seen. Resets when the server is reset.
public static Dictionary lastSeen
return DateTime>.Dictionary

left public static property

This needs a better description. What does left do?
public static Dictionary left
return string>.Dictionary

name public property

public string name
return string

players public static property

public static ThreadedBindingList players
return ThreadedBindingList