Package lacewing :: Module server :: Class ServerProtocol
[frames] | no frames]

Class ServerProtocol

source code

twisted.internet.protocol.BaseProtocol --+        
                                         |        
        twisted.internet.protocol.Protocol --+    
                                             |    
                         protocol.BaseProtocol --+
                                                 |
                                                ServerProtocol

The server protocol.

Instance Methods
 
connectionMade(self)
When a connection is made, a timeout timer is started, and if the user does not request connection acceptance within reasonable time, disconnect (to prevent flood attacks).
source code
 
ping(self, timeOut=None)
Ping the client with the given timeout.
source code
 
connectionLost(self, reason)
Once the connection is lost, put back the client ID into the pool, and remove the client from all the channels it has signed on to.
source code
 
dataReceived(self, data)
Called whenever data is received.
source code
 
loaderReceived(self, loader, isDatagram=False)
Called when a packet is received.
source code
 
sendLoader(self, loader, asDatagram=False)
Sends a packetloader to the client
source code
 
disconnect(self, response=None, *arg, **kw)
Disconnect the the user for a specific reason.
source code
 
warn(self, response, warning='', name=None, channel=None)
Notify the client about a denial.
source code
 
sendMessage(self, message, subchannel, channel=None, typeName=None, asObject=False, asDatagram=False)
Send a direct message to the client.
source code
 
leaveChannel(self, channel)
Remove the client from a specific channel.
source code
 
joinChannel(self, channelName, hidden=False, autoClose=False)
Add the client to a new channel.
source code
 
setName(self, name)
Set the name of the client and notify it about it.
source code
 
sendChannelList(self, channels)
Sends a list of channels and their peer count to the other end of the connection.
source code
 
connectionAccepted(self, welcome)
Called when the server has accepted the requested connection.
source code
 
loginAccepted(self, name)
Called when the server has accepted the requested name.
source code
 
channelListSent(self)
Called after a requested channel list is sent.
source code
 
nameChanged(self, name)
Called when the client changed name (after logging in).
source code
 
messageReceived(self, message)
Called when a client message arrives.
source code
 
channelMessageReceived(self, channel, message)
Called when the client sends a channel message.
source code
 
privateMessageReceived(self, channel, recipient, message)
Called when the client has sent a private message
source code
 
channelJoined(self, channel)
Called when the client has joined a new channel.
source code
 
channelLeft(self, channel)
Called when the client has left a channel.
source code
 
pongReceived(self, latency)
Called when a ping response has been received.
source code
 
masterActionExecuted(self, channel, peer, action)
Called when after a master action has been executed.
source code
bool
acceptLogin(self, name)
Cancels the client login if False is returned.
source code
bool
acceptNameChange(self, name)
Cancels the client name change if False is returned.
source code
bool
acceptConnection(self, welcome)
Cancels the connection accept response if False is returned.
source code
bool
acceptChannelMessage(self, channel, message)
Cancels the channel message if False is returned.
source code
bool
acceptPrivateMessage(self, channel, recipient, message)
Cancels the private message if False is returned.
source code
bool
acceptChannelListRequest(self)
Cancels the sending of the channel list if False is returned.
source code
bool
acceptChannelJoin(self, channelName)
Cancels the channel join accept response if False is returned.
source code
bool
acceptChannelLeave(self, channel)
Cancels the channel leave accept response if False is returned.
source code
bool
acceptMasterAction(self, channel, peer, action)
Cancels a master action if False is returned.
source code

Inherited from protocol.BaseProtocol: validName

Inherited from twisted.internet.protocol.Protocol: __provides__

Inherited from twisted.internet.protocol.BaseProtocol: __providedBy__, makeConnection

Class Variables

Inherited from protocol.BaseProtocol: revision, udpEnabled

Inherited from twisted.internet.protocol.Protocol: __implemented__

Inherited from twisted.internet.protocol.BaseProtocol: connected, transport

Instance Variables
  latency = None
The latency between the server and client.
  datagramPort = None
The UDP port that the connection sends/receives data on.

Inherited from protocol.BaseProtocol: channels, id, isAccepted, loggedIn, name, privateAllowed

Method Details

connectionMade(self)

source code 

When a connection is made, a timeout timer is started, and if the user does not request connection acceptance within reasonable time, disconnect (to prevent flood attacks).

Overrides: twisted.internet.protocol.BaseProtocol.connectionMade

ping(self, timeOut=None)

source code 

Ping the client with the given timeout.

Parameters:
  • timeOut - The number of seconds the client has to respond to the ping.

connectionLost(self, reason)

source code 

Once the connection is lost, put back the client ID into the pool, and remove the client from all the channels it has signed on to.

Overrides: twisted.internet.protocol.Protocol.connectionLost

dataReceived(self, data)

source code 

Called whenever data is received.

Use this method to translate to a higher-level message. Usually, some callback will be made upon the receipt of each complete protocol message.

Parameters:
  • data - a string of indeterminate length. Please keep in mind that you will probably need to buffer some data, as partial (or multiple) protocol messages may be received! I recommend that unit tests for protocols call through to this method with differing chunk sizes, down to one byte at a time.
Overrides: twisted.internet.protocol.Protocol.dataReceived
(inherited documentation)

loaderReceived(self, loader, isDatagram=False)

source code 

Called when a packet is received.

Parameters:
  • isDatagram - True if the message recieved was sent using UDP.
Overrides: protocol.BaseProtocol.loaderReceived
(inherited documentation)

sendLoader(self, loader, asDatagram=False)

source code 

Sends a packetloader to the client

Parameters:
  • loader - The packetloader to send.
  • asDatagram - True if the packet should be sent as a datagram packet
Overrides: protocol.BaseProtocol.sendLoader

sendMessage(self, message, subchannel, channel=None, typeName=None, asObject=False, asDatagram=False)

source code 

Send a direct message to the client.

Parameters:
  • subchannel - The subchannel of the message in the range 0-256
  • typeName - If not specified, the type will be automatically detected (see lacewing.packetloaders.common.DATA_TYPES for possible values)
  • message (str/number/ByteReader)

leaveChannel(self, channel)

source code 

Remove the client from a specific channel.

Parameters:
  • channel (ServerChannel object) - The channel to remove the client from.

joinChannel(self, channelName, hidden=False, autoClose=False)

source code 

Add the client to a new channel. If the channel does not already exist, it is created.

Parameters:
  • hidden - If this connection is creating the channel, this will hide it from channel listing
  • autoClose - If this connection is creating the channel, this will close the channel when the connection leaves

sendChannelList(self, channels)

source code 

Sends a list of channels and their peer count to the other end of the connection.

Parameters:
  • channels - List of 2-item tuples (channelName, peerCount)

connectionAccepted(self, welcome)

source code 

Called when the server has accepted the requested connection.

Parameters:

loginAccepted(self, name)

source code 

Called when the server has accepted the requested name.

Parameters:
  • name (str object) - The name of the client.

nameChanged(self, name)

source code 

Called when the client changed name (after logging in).

Parameters:
  • name (str) - The name the client has changed to.

messageReceived(self, message)

source code 

Called when a client message arrives.

Parameters:

channelMessageReceived(self, channel, message)

source code 

Called when the client sends a channel message.

Parameters:

privateMessageReceived(self, channel, recipient, message)

source code 

Called when the client has sent a private message

Parameters:

channelJoined(self, channel)

source code 

Called when the client has joined a new channel.

Parameters:
  • channel - The channel the client has joined.

channelLeft(self, channel)

source code 

Called when the client has left a channel.

Parameters:
  • channel - The channel the client has left.

pongReceived(self, latency)

source code 

Called when a ping response has been received.

Parameters:
  • latency - Round-trip time in seconds between the client and the server.

masterActionExecuted(self, channel, peer, action)

source code 

Called when after a master action has been executed.

Parameters:
  • channel - The channel the action took place in
  • peer - The peer the action was executed on
  • action (Currently, only {pylacewing.constants.MASTER_KICK}) - The action the master requested

acceptLogin(self, name)

source code 

Cancels the client login if False is returned. Useful if the server specifies client names.

Parameters:
  • name - The requested client name.
Returns: bool
Return False to cancel client login.

acceptNameChange(self, name)

source code 

Cancels the client name change if False is returned. Useful if the server specifies client names.

Parameters:
  • name - The requested client name.
Returns: bool
Return False to cancel name change.

acceptConnection(self, welcome)

source code 

Cancels the connection accept response if False is returned. Useful for banning.

Parameters:
Returns: bool
Return False to cancel connection acceptance.

acceptChannelMessage(self, channel, message)

source code 

Cancels the channel message if False is returned. Useful for blocking invalid messages.

Parameters:
Returns: bool
Return False to stop the channel message before it is sent.

acceptPrivateMessage(self, channel, recipient, message)

source code 

Cancels the private message if False is returned. Useful for blocking invalid messages.

Parameters:
Returns: bool
Return False to stop the channel message before it is sent.

acceptChannelListRequest(self)

source code 

Cancels the sending of the channel list if False is returned. Useful for servers with a strict policy.

Returns: bool
Return False to send no channel list.

acceptChannelJoin(self, channelName)

source code 

Cancels the channel join accept response if False is returned. Useful for channel-less servers.

Parameters:
  • channelName - The name of the channel.
Returns: bool
Return False to cancel channel join acceptance.

acceptChannelLeave(self, channel)

source code 

Cancels the channel leave accept response if False is returned. Useful if the client may not leave the current channel.

Parameters:
  • channel - The channel the client is leaving.
Returns: bool
Return False to cancel channel join acceptance.

acceptMasterAction(self, channel, peer, action)

source code 

Cancels a master action if False is returned. Useful for blocking some specific master actions.

Parameters:
  • channel - The channel the action is taking place in.
  • peer - The peer this action is executed on.
  • action (Currently, only {pylacewing.constants.MASTER_KICK}) - The action the master has requested.
Returns: bool