NetDragons Baseball Posters | New Stock Sells
Games | Free Web Hosting | DVD | Books | Shop | Posters
Google
Name
Password
Save Password?



[-]NetDragons.com
[-]Games
 | [-]24 Hour Games
 |  | [+]Nelzan
 |  | [+]Space Frag I
 |  | [-]GNet Server
 |  |  | [+]Commands
 |  |  | [+]Forum
 |  |  | [+]Protocol
 |  |  | [-]Source
 |  | [+]About
 |  | [+]Forum
 |  | [+]License
 | [+]Cards of Tridala
 | [+]Flash Games
 | [+]Vagabond's Quest+
 | [+]Vagabond's Quest v.2
 | [+]Projects
[+]NetDragons.com Live!
[+]Reward Center
[+]Software Center
[+]Company Information
[+]Personal Services
[+]Member Directory
[+]Free E-mail
[+]Buy Cool Stuff
[+]Posters
[+]Your Privacy

Class User


[ Source | Index | Back to GNS ]

public class User
extends Thread
User - Stores user data and provides the user with an connection to interact with.

Each users is given it's own thread to run in. If the user fails to send data to the server in 5 mins the connection will automatically close. This will handle all the commands sent from the client, and handle sending all the data from the server back to the client.


Variable Index

 o active
Indicated if the players connection is active.
 o gameID
The game or client ID that the user is using.
 o id
The users ID number.
 o in
Allows the server to communicate with the client.
 o log
Used to log major commands to PATH/log/access_log.
 o mode
Used to hold information set by
 o myGroup
Instnace of the current users group.
 o name
The users name or handle.
 o out
Allows the client to communicate with the server.
 o server
Instance of the server so we can perform server level actions.
 o soc
Open socket connecting the client and server.
 o type
Type of incoming data.

Constructor Index

 o User(Socket, logger, gnsd)
Creates a new instance of a User.

Method Index

 o getAddress()
Gets the host address of the client's socket.
 o getGameID()
Gets the users Game/Client ID number.
 o getID()
Gets the users ID number.
 o getMode()
Gets the users mode.
 o getUserName()
Gets the users name.
 o handle(String)
Handles input from the client when it's presented with data.
 o handleCommand(String)
Handles all the commands the client could posible send.
 o handleData(String)
Handles broadcasting of data to all members of a group.
 o join(Group)
Allows the user to join a group.
 o join(int)
Uses the server level commands to join a group.
 o joinNew(String)
Allows the user to make a new group.
 o login(String)
Allows the user to Login to the network and become authinticated.
 o logout(String)
Causes the client connection to be closed.
 o part()
Allows a user to leave a channel.
 o run()
Handles the execution of the users thread.
 o send(String)
Sends a message to the client.
 o sendGameCommand(String)
Broadcast game information to all clients in a group.
 o sendPrivMessage(String)
Sends a private message to a user.
 o toInt(String)
Converts a String to an int;

Variables

 o soc
 private Socket soc
Open socket connecting the client and server. This is used for all incoming and out going traffic.

 o in
 private DataInputStream in
Allows the server to communicate with the client.

 o out
 private DataOutputStream out
Allows the client to communicate with the server.

 o log
 private logger log
Used to log major commands to PATH/log/access_log. This will log @connect, @login, @join, @joinnew, @list, @part, and @logout. Logs are timestamped via time_t, information about the user's host, command, and other useful information is given.

 o id
 private int id
The users ID number. This is set to -1 if the user is not authenticated.

 o name
 private String name
The users name or handle. This will be null until the user has authenticated.

 o gameID
 private int gameID
The game or client ID that the user is using. This will be null until the user has authenticated. Used so a number of different clients can connet to the server without them conflicting.

 o mode
 private String mode
Used to hold information set by @setmode. This can store information to be transmited on joining the network, this can be used for control reasons, or just to transmit extra data.

 o type
 private char type
Type of incoming data. Used to see if there is a leading @ or #.

 o server
 private gnsd server
Instance of the server so we can perform server level actions. This includes joining groups, getting group lists, getting user counts, etc.

 o myGroup
 private Group myGroup
Instnace of the current users group. This is so the user can send data to the group, can leave the group, etc. This will be null until the user has joined a channel.

 o active
 private boolean active
Indicated if the players connection is active.

Constructors

 o User
 public User(Socket s,
             logger l,
             gnsd g) throws IOException
Creates a new instance of a User. Sets up the input stream and output stream, through buffers, from the client's socket. Also sets the timeout to 5 minutes.

Parameters:
s - the client's socket.
l - Instance of logger, use to log commands.
g - Instance of the server so we can perform server level actions.

Methods

 o run
 public void run()
Handles the execution of the users thread. We sit in an infinate loop and read data from the input stream. The thread is only borken when the client's connection is broken. Server is hardcoded to read UTF data only.

Overrides:
run in class Thread
 o send
 public void send(String msg)
Sends a message to the client. Data is sent to the client in UTF format.

Parameters:
msg - the message to send.
 o join
 public void join(Group g)
Allows the user to join a group. A User can only be in one group at a time, so the server is carefully crafted to make sure part is called before we join a group.

Parameters:
g - the group to join.
 o getUserName
 public String getUserName()
Gets the users name.

Returns:
the name of the user.
 o getAddress
 public String getAddress()
Gets the host address of the client's socket. This is used for logging. Later versions of the server may allow a @whois command so direct client to client communication can be used.

Returns:
the host address of the client.
 o getID
 public int getID()
Gets the users ID number.

Returns:
the users ID number.
 o getMode
 public String getMode()
Gets the users mode.

Returns:
the users mode.
 o getGameID
 public int getGameID()
Gets the users Game/Client ID number.

Returns:
the users game/client ID number.
 o handle
 private void handle(String message)
Handles input from the client when it's presented with data. The String needs to begin with @ (a command) or # (broadcast) for the server to handle the information. Depending on which type of data is sent the proper handling function is called. If the String does not start with a known char, an error is returned to the client.

See Also:
handleCommand, handleData
 o handleCommand
 private void handleCommand(String data)
Handles all the commands the client could posible send. For a list of all clients visit http://www.netdragons.com/games/24/gns/commands/. If the command isn't understood, an error is returned to the client.

Parameters:
data - data given from the client.
 o handleData
 private void handleData(String data)
Handles broadcasting of data to all members of a group. If the user is not authenticated, or is not in a group, and error is returned to the client.

Parameters:
data - the data to broadcast.
 o sendGameCommand
 private void sendGameCommand(String data)
Broadcast game information to all clients in a group. This is used to transmit informational data, such as a ship type, weapon change, etc. most data will be send through handleData.

Parameters:
data - the data to broadcast.
See Also:
handleData
 o sendPrivMessage
 private void sendPrivMessage(String data)
Sends a private message to a user. This only works when the user is in the same group that you are.

Parameters:
data - the data to private message
 o join
 private void join(int cID)
Uses the server level commands to join a group. If the user is not authenticated, an error is returned to the client. If the group does not exist, an error is returned to the client. To make sure the user is not in a group, the part() function is called.

Parameters:
cID - group ID to join.
See Also:
part
 o joinNew
 private void joinNew(String data)
Allows the user to make a new group. This works much the same way as the join command, and returns errors the same. To make sure we don't create two group with the same ID, we check to make sure the group doesn't exist. If it does already exist, it is just like using join(id);

Parameters:
data - new channel information
See Also:
join
 o part
 private synchronized void part()
Allows a user to leave a channel. Makes sure that the user is in a group to begin with, and if they are, they are removed from it. myGroup is set to null to finish the operation.

See Also:
myGroup
 o login
 private void login(String data)
Allows the user to Login to the network and become authinticated. Uses a server level command, and checks to make sure the name is valid, i.e. not "logout". If authintication fails, an error is returned to the client and they are disconnected. If the login work, id, gameID, and and name are all set.

Parameters:
data - user data, "userID`password`gameID"
See Also:
id, gameID, name
 o logout
 private void logout(String msg)
Causes the client connection to be closed. If posible the client will be notified that the connection is being closed.

Parameters:
msg - Message to send to client.
 o toInt
 private int toInt(String s)
Converts a String to an int;

Parameters:
s - The String to be converted
Returns:
an int value from s
ND: VQ+, Mail, Shop, Free Web Hosting Free Stock Screener

Free Stock Screener
Copyrighted �, 2000, 2001 by NetDragons.com
Last Updated Sunday, March 21, 1999 - 23:54 EST