edu.cuny.cat.server
Class ClientBehaviorController

java.lang.Object
  extended by edu.cuny.cat.server.ClientBehaviorController
All Implemented Interfaces:
edu.cuny.config.param.Parameterizable, edu.cuny.obj.Resetable

public class ClientBehaviorController
extends java.lang.Object
implements edu.cuny.config.param.Parameterizable, edu.cuny.obj.Resetable

allows the game server to take actions after a client does something a certain number of times, which may cause the game server unstable. Currently, two behaviors are monitored, reconnection and transaction request made outside rounds.

Parameters

base.reconnection
int (5 by default)
(the maximal number of times a client may reconnect to the game server after dropping out)
base.request_at_wrong_time
int (10 by default)
(the number of requests made by a client at a wrong time that would lead to a daily ban.)

Default Base

behavior

Version:
$Revision: 1.8 $
Author:
Jinzhong Niu

Field Summary
protected  java.util.Map<java.lang.String,java.util.Map<java.lang.String,edu.cuny.cat.server.ClientBehaviorController.Counter>> behaviorRecords
           
static java.lang.String CONNECTION_BANNING_PENALTY
           
static java.lang.String DAY_BANNING_PENALTY
          penalty types
static int DEFAULT_MAX_NUMBER_OF_RECONNECTION
          default times of bad behaviors to incur a penalty
static int DEFAULT_MAX_NUMBER_OF_REQUEST_AT_WRONG_TIME
           
protected  int maxReconnection
           
protected  int maxWrongRequest
           
static java.lang.String OTHER_PENALTY
           
static java.lang.String P_DEF_BASE
           
static java.lang.String P_RECONNECTION
          parameters
static java.lang.String P_REQUEST_AT_WRONG_TIME
           
protected  java.util.Map<java.lang.String,java.util.Map<java.lang.String,edu.cuny.cat.server.ClientBehaviorController.Counter>> penaltyRecords
           
static java.lang.String RECONNECTION
          problem-causing behavior types
static java.lang.String REQUEST_AT_WRONG_TIME
           
 
Constructor Summary
ClientBehaviorController()
           
 
Method Summary
 void addPenalty(java.lang.String clientId, java.lang.String penaltyType)
          add one unit of the specified penalty.
 int getPenalty(java.lang.String clientId, java.lang.String penaltyType)
           
 java.lang.String getPenaltyType(java.lang.String behaviorType)
           
 void observe(java.lang.String clientId, java.lang.String behaviorType)
          updates records after a bad behavior is observed.
 void penaltyExecuted(java.lang.String clientId, java.lang.String penaltyType)
          fulfills the specified penalty one on a game client.
 void reset()
           
 void setup(edu.cuny.config.param.ParameterDatabase parameters, edu.cuny.config.param.Parameter base)
           
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

RECONNECTION

public static final java.lang.String RECONNECTION
problem-causing behavior types

See Also:
Constant Field Values

REQUEST_AT_WRONG_TIME

public static final java.lang.String REQUEST_AT_WRONG_TIME
See Also:
Constant Field Values

DAY_BANNING_PENALTY

public static final java.lang.String DAY_BANNING_PENALTY
penalty types

See Also:
Constant Field Values

CONNECTION_BANNING_PENALTY

public static final java.lang.String CONNECTION_BANNING_PENALTY
See Also:
Constant Field Values

OTHER_PENALTY

public static final java.lang.String OTHER_PENALTY
See Also:
Constant Field Values

P_RECONNECTION

public static final java.lang.String P_RECONNECTION
parameters

See Also:
Constant Field Values

P_REQUEST_AT_WRONG_TIME

public static final java.lang.String P_REQUEST_AT_WRONG_TIME
See Also:
Constant Field Values

P_DEF_BASE

public static final java.lang.String P_DEF_BASE
See Also:
Constant Field Values

DEFAULT_MAX_NUMBER_OF_RECONNECTION

public static final int DEFAULT_MAX_NUMBER_OF_RECONNECTION
default times of bad behaviors to incur a penalty

See Also:
Constant Field Values

DEFAULT_MAX_NUMBER_OF_REQUEST_AT_WRONG_TIME

public static final int DEFAULT_MAX_NUMBER_OF_REQUEST_AT_WRONG_TIME
See Also:
Constant Field Values

maxReconnection

protected int maxReconnection

maxWrongRequest

protected int maxWrongRequest

behaviorRecords

protected java.util.Map<java.lang.String,java.util.Map<java.lang.String,edu.cuny.cat.server.ClientBehaviorController.Counter>> behaviorRecords

penaltyRecords

protected java.util.Map<java.lang.String,java.util.Map<java.lang.String,edu.cuny.cat.server.ClientBehaviorController.Counter>> penaltyRecords
Constructor Detail

ClientBehaviorController

public ClientBehaviorController()
Method Detail

setup

public void setup(edu.cuny.config.param.ParameterDatabase parameters,
                  edu.cuny.config.param.Parameter base)
Specified by:
setup in interface edu.cuny.config.param.Parameterizable

observe

public void observe(java.lang.String clientId,
                    java.lang.String behaviorType)
updates records after a bad behavior is observed.

Parameters:
clientId - the client that did the observed the activity
behaviorType - the type of behavior that may lead to penalties

addPenalty

public void addPenalty(java.lang.String clientId,
                       java.lang.String penaltyType)
add one unit of the specified penalty.

Parameters:
clientId -
penaltyType -

getPenalty

public int getPenalty(java.lang.String clientId,
                      java.lang.String penaltyType)
Parameters:
clientId -
penaltyType -
Returns:
units of the specified penalty pending on the client. Non-positive values mean no penalty to impose.

getPenaltyType

public java.lang.String getPenaltyType(java.lang.String behaviorType)
Parameters:
behaviorType -
Returns:
the type of penalty to impose due to the specified behavior.
See Also:
getPenaltyLevel(String)

penaltyExecuted

public void penaltyExecuted(java.lang.String clientId,
                            java.lang.String penaltyType)
fulfills the specified penalty one on a game client.

Parameters:
clientId - the client to be punished
penaltyType - the type of penalty to fulfill

reset

public void reset()
Specified by:
reset in interface edu.cuny.obj.Resetable

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object