multiverse.server.plugins
Class VoicePlugin

java.lang.Object
  extended by multiverse.server.engine.EnginePlugin
      extended by multiverse.server.plugins.VoicePlugin
All Implemented Interfaces:
MessageCallback, StatusMapCallback, ClientConnection.AcceptCallback, ClientConnection.MessageCallback, VoiceSender

public class VoicePlugin
extends EnginePlugin
implements VoiceSender, ClientConnection.AcceptCallback, ClientConnection.MessageCallback

Plugin to handle voice channels


Nested Class Summary
(package private)  class VoicePlugin.DespawnedHook
          DespawnedHook asks the conneciton manager if the message subject oid is a positional group member, and if it is, and it has an InterpolatedWorldNode, it calls the group's removeTrackedPerceiver method, and also removes the subject oid from the perception filter.
(package private)  class VoicePlugin.GetPluginStatusHook
           
(package private)  class VoicePlugin.InstanceUnloadedHook
          Used for both instance unloaded and instance deleted.
(package private)  class VoicePlugin.LoginHook
          This is used exclusively to support voice bots for large-scale tests.
(package private)  class VoicePlugin.PerceptionHook
          PerceptionHook processes PerceptionMessages, which incorporate lists of perceived objects gained and lost by the target object.
(package private)  class VoicePlugin.RelayUpdatePlayerIgnoreListHook
          A hook to handle update ignore list message contents originating with the client, and passed on by the proxy.
(package private)  class VoicePlugin.SpawnedHook
          SpawnedHook asks the conneciton manager if the message subject oid is a positional group member, and if it is, it calls trackNewPerceiver to add it to the set of members whose perceived oids are tracked.
(package private)  class VoicePlugin.Updater
          A class containing a thread that interpolates the locations of all PositionalVoiceGroup members once every second.
(package private)  class VoicePlugin.UpdateWorldNodeHook
          UpdateWorldNodeHook asks the conneciton manager if the message subject oid is a positional group member, and if it is, and it has an InterpolatedWorldNode, it calls the group's updateWorldNode method.
(package private)  class VoicePlugin.VoiceClientMessageHook
          A hook to process ExtensionMessages whose msgType is VoiceClient.MSG_TYPE_VOICECLIENT.
static class VoicePlugin.VoiceConManager
          A class with locking to manage the Maps and Sets of connections.
 
Nested classes/interfaces inherited from class multiverse.server.engine.EnginePlugin
EnginePlugin.DeleteHook, EnginePlugin.DeleteSubObjHook, EnginePlugin.GenerateSubObjectHook, EnginePlugin.GetPropertyMessage, EnginePlugin.LoadHook, EnginePlugin.LoadSubObjHook, EnginePlugin.PluginActivateHook, EnginePlugin.PluginStateMessage, EnginePlugin.SaveHook, EnginePlugin.SaveSubObjHook, EnginePlugin.SetPropertyMessage, EnginePlugin.SubObjData, EnginePlugin.TransferFilter, EnginePlugin.TransferObjectMessage, EnginePlugin.UnloadHook, EnginePlugin.UnloadSubObjHook
 
Field Summary
protected static boolean allowVoiceBots
          If this is true, we subscribe to login messages and pass on login notifications.
private static float audibleRadius
          Can hear positional sounds up to 20 meters away
static boolean checkAuthToken
           
private  ClientTCPMessageIO clientTCPMessageIO
          The engine that handles TCP message traffic to all the clients.
private  VoicePlugin.VoiceConManager conMgr
           
static CountLogger.Counter countAllocateVoiceReceived
           
static CountLogger.Counter countAllocateVoiceSent
           
private static CountLogger.Counter countDataFramesReceived
           
private static CountLogger.Counter countDataFramesSent
           
static CountLogger.Counter countDeallocateVoiceReceived
           
static CountLogger.Counter countDeallocateVoiceSent
           
private  CountLogger countLogger
          Counters that get logged every second
private static CountLogger.Counter countPacketsIgnored
           
private static CountLogger.Counter countPacketsReceived
           
private static CountLogger.Counter countPacketsSent
           
static CountLogger.Counter countSendLoginStatus
           
private static CountLogger.Counter countSeqNumGaps
           
protected static boolean createGroupWhenReferenced
          If this is true, we'll synthesize the group and/or group member when an auth packet comes in.
static TimeHistogram dataSendHistogram
           
protected static float hystericalMargin
          The hysteresis constant: don't change whether a pair of positonal group members are in-radius of each other if the distance is within this distance of the audibleRadius.
protected static VoicePlugin instance
          singleton
static int lengthBytes
          There are two bytes in the length prefixed to a TCP message
protected  Lock lock
           
private  Set<VoiceConnection> loginStatusEventReceivers
          A map of connections that will receive login/logout events - - only used by the voice bot system.
private  short loginStatusSeqNum
          The next sequence number for a login status message
static int maxVoiceChannels
          The server is supposed to run things so no client ever has more than this number of voice channels.
static byte opcodeAggregatedData
          An aggregated data packet contains a number of data packets.
static byte opcodeAllocateCodec
          Allocate a voice.
static byte opcodeAllocatePositionalCodec
          This has exactly the same payload as AllocateCodec, but says that the voice should be positional.
static byte opcodeAuthenticate
          The authenticate packet must be the first one received by the voice plugin on any new connection from a client.
static byte opcodeChangeIgnoredStatus
          An opcode sent exclusively from the client to the server that marks a collection of oids as ignored or not ignored.
static byte opcodeData
          A data packet, consisting of a 4-byte header followed by the bytes of the data frame.
static byte opcodeDeallocate
          Deallocate the voice number.
static int opcodeHighest
           
static byte opcodeLoginStatus
          An opcode sent exclusively from the server to the client, and used only to support synchronization between voice bots and test clients.
static String[] opcodeNames
          Used in logging messages
static byte opcodeReconfirmCodec
          This has exactly the same payload as AllocateCodec, but is with lossy transports like UDP to send the opcode parameters every second or so.
static byte opcodeVoiceUnallocated
          All voices start out unallocated
protected  PerceptionFilter perceptionFilter
           
protected  long perceptionSubId
           
static TimeHistogram processPacketHistogram
           
private  boolean recordVoices
          Should we record all voices as we run? ??? TBD: We'll need to make this more selective in the production version, via an API call
static boolean runHistograms
           
protected  boolean running
           
private  String serverVersion
          The server version to send to clients
static int[] speexNarrowBandFrameSize
          This array is indexed by Speex narrow-band mode, and gives the narrow-band frame size for that mode.
static int[] speexWideBandFrameSize
           
protected  VoicePlugin.Updater updater
           
protected  Thread updaterThread
           
static TimeHistogram voiceAllocHistogram
           
static TimeHistogram voiceDeallocHistogram
           
static int[] voiceMsgSize
          This gives the number of bytes in the message excluding the length, except for the data case, where it gives the number of bytes in the header, but not including the data itself
static byte voicePacketHeaderSize
          All voice packets start with 4 bytes: o 16-bit sequence number, increased by one for each successive transmission for this voice.
private  Integer voicePort
          The port number we're listening on
 
Fields inherited from class multiverse.server.engine.EnginePlugin
deleteSubObjectSubscription, dumpAllThreadSubscription, dumpAllThreadSubscriptionLock, loadSubObjectSubscription, MSG_TYPE_DUMP_ALL_THREAD_STACKS, MSG_TYPE_GET_PROPERTY, MSG_TYPE_PLUGIN_STATE, MSG_TYPE_SET_PROPERTY, MSG_TYPE_SET_PROPERTY_NONBLOCK, MSG_TYPE_TRANSFER_OBJECT, pluginStateSubscription, propertySubscription, saveSubObjectSubscription, selectionFilter, selectionSubscription, setSubObjectPersistenceSubscription, subObjectSubscription, unloadSubObjectSubscription
 
Fields inherited from interface multiverse.msgsys.MessageCallback
NO_FLAGS, RESPONSE_EXPECTED
 
Constructor Summary
VoicePlugin()
          The VoicePlugin accepts connections from game clients who have been supplied the IP and port number to contact by the initial game system login.
 
Method Summary
 void acceptConnection(ClientConnection con)
          The callback from ClientTCPIO invoked when a connection is established.
 void addGroup(long groupOid, VoiceGroup group)
          Inform the VoicePlugin about the existance of a voice group.
protected  void addToPerceptionFilter(long playerOid)
          Internal method that adds the playerOid to the list of oids for which the perception filter will send perception messages.
 void connectionReset(ClientConnection con)
          In response to a ClientConnection being closed, deallocate all voices in use by the connection, and remove the listeners, and close record stream if it's open.
static int encodedFrameSizeForMode(int mode, boolean wideBand)
          Return the total frame size for narrow or wide-band mode given
static int encodedFrameSizeFromFirstByte(byte b)
          Return the frame size for the band/mode specified by the first byte of the Speex frame.
protected  void expungeVoiceClient(long playerOid)
          Remove the voice client associated with the playerOid from the VoicePlugin data structures.
protected  void expungeVoiceClient(long playerOid, VoiceConnection con)
          Remove the voice client associated with the playerOid from the VoicePlugin data structures.
protected  VoiceGroup findVoiceGroup(long groupOid)
          Return the group for groupOid, having checked to see that the group exists and contains the player.
 String formatCon(ClientConnection con)
          Produce a string description of the ClientConnection object.
 VoiceConnection getConnectionData(ClientConnection con)
          Get the VoiceConnection object associated with the ClientConnection.
static VoicePlugin getInstance()
           
protected  GroupMember getPlayerMember(long playerOid)
          Get the GroupMember associated with the playerOid, or null if there is none.
private  void handleVoiceProperties()
          A method to encache the voice-specific members of multiverse.properties.
static short incSeqNum(short original)
          Increment the short seqNum so that it wraps around properly.
static short incSeqNum(short original, int byWhat)
          Increment the short seqNum so that it wraps around properly.
protected  void initializeIgnoreList(VoiceConnection playerCon)
           
 void onActivate()
          Register the hooks and create the subscriptions for the VoicePlugin.
static String opcodeString(byte opcode)
          Return a string representation of the opcode number; used for logging.
protected  BufferedOutputStream openSpeexVoiceFile(long oid)
          Internal method used when writing Speex voice files.
private  Long parseLongOrNull(String s)
           
 void processAuthenticationPacket(VoiceConnection playerCon, MVByteBuffer buf)
          Check to see of the auth packet contains the proper credentials, and if so, create a group member in the specified group.
protected  void processIgnoreListChangeMessage(VoiceConnection playerCon, MVByteBuffer buf)
          Change the ignored status of a set of potential speakers.
 void processPacket(ClientConnection con, MVByteBuffer buf)
          Process a packet received from a player.
protected  void removeFromPerceptionFilter(long playerOid)
          Internal method that removes the playerOid from the list of oids for which the perception filter will send perception messages.
 void removeGroup(long groupOid)
          Remove a group.
 void removePlayerFromGroup(VoiceConnection playerCon)
          Remove the player identified by the argument from the group it belongs to.
 void sendAllocateVoice(VoiceConnection speaker, VoiceConnection listener, byte voiceNumber, boolean positional)
          Send an allocate voice packet to the listener, representing a voice channel from the speaker to the listener.
 void sendAllocateVoice(VoiceConnection speaker, VoiceConnection listener, byte voiceNumber, byte opcode)
          Send an allocate voice packet to the listener, representing a voice channel from the speaker to the listener.
 void sendDeallocateVoice(VoiceConnection speaker, VoiceConnection listener, byte voiceNumber)
          Send a message to the connection deallocating the voice with the given number.
 void sendExtensionMessage(WorldManagerClient.ExtensionMessage msg)
          Send an ExtensionMessage.
 void sendLoginStatus(VoiceConnection receiver, long playerOid, boolean login)
          Send a login status message, telling the receiver that a player has logged in.
protected  void sendLoginStatusToReceivers(long playerOid, boolean login)
          Used only when running voice bots.
private  void sendPacketToListener(VoiceConnection listener, MVByteBuffer buf)
          Send a packet, whose contents is in the buf, to the listener.
 void sendVoiceFrame(VoiceConnection speaker, VoiceConnection listener, byte opcode, byte voiceNumber, MVByteBuffer sourceBuf, short pktLength)
          Send a message containing voice frame(s) to the listener.
protected  void trackNewPerceiver(PositionalGroupMember member)
          Internal method to add the positional group member to the set of member whose perceived players will be tracked.
protected  void writeSpeexData(BufferedOutputStream recordSpeexStream, byte[] buf, int startIndex, int byteCount)
          Write a single Speex frame to the stream, from the byte array
 
Methods inherited from class multiverse.server.engine.EnginePlugin
activate, createMBeanInstance, createSubscription, getHookManager, getMessageHandler, getName, getObjectLockManager, getObjectProperties, getObjectProperties, getObjectProperty, getPercentCPULoad, getPluginAvailable, getPluginInfo, getPluginNamespaces, getPluginState, getPluginStatus, getPluginType, getPropertyImpl, getStatusMap, handleMessage, handleMessageImpl, logDepsOutstanding, processKeysAndValues, registerActivateHook, registerDeleteHook, registerLoadHook, registerPluginNamespace, registerPluginNamespaces, registerPluginNamespaces, registerPluginNamespaces, registerSaveHook, registerTransferHook, registerUnloadHook, sendSubObjectResponse, sendSubObjectResponse, sendSubObjectResponse, setMessageHandler, setName, setObjectProperties, setObjectProperties, setObjectPropertiesNoResponse, setObjectPropertiesNoResponse, setObjectProperty, setObjectPropertyNoResponse, setPercentCPULoad, setPluginAvailable, setPluginInfo, setPluginType, setPropertyImpl, transferObject
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

voicePacketHeaderSize

public static final byte voicePacketHeaderSize
All voice packets start with 4 bytes: o 16-bit sequence number, increased by one for each successive transmission for this voice. o 8-bit opcode byte o 8-bit voice number

See Also:
Constant Field Values

opcodeVoiceUnallocated

public static final byte opcodeVoiceUnallocated
All voices start out unallocated

See Also:
Constant Field Values

opcodeAuthenticate

public static final byte opcodeAuthenticate
The authenticate packet must be the first one received by the voice plugin on any new connection from a client. The voice plugin maintains a map of the IP/port number to the oid of the client, used to validate traffic. The packet contains the string authentication token, the oid of the player; the oid of the group the player is signing up to; and a bool saying whether voice packets from this connection should be sent back to this connection. Total size is 2 + 1 + 1 + 8 + 8 + 1 + 4 = 25 bytes plus number of bytes in the authToken string.

See Also:
Constant Field Values

opcodeAllocateCodec

public static final byte opcodeAllocateCodec
Allocate a voice. Apart from the header, the payload is the 8-byte OID of the object emitting the sound. Size is 12 bytes.

See Also:
Constant Field Values

opcodeAllocatePositionalCodec

public static final byte opcodeAllocatePositionalCodec
This has exactly the same payload as AllocateCodec, but says that the voice should be positional.

See Also:
Constant Field Values

opcodeReconfirmCodec

public static final byte opcodeReconfirmCodec
This has exactly the same payload as AllocateCodec, but is with lossy transports like UDP to send the opcode parameters every second or so. Size is 12 bytes.

See Also:
Constant Field Values

opcodeDeallocate

public static final byte opcodeDeallocate
Deallocate the voice number. A voice number must be deallocated before it can be reused. There is no additional data. This is used both when a client signs off, and when the microphone goes quiet. A total of 4 bytes.

See Also:
Constant Field Values

opcodeData

public static final byte opcodeData
A data packet, consisting of a 4-byte header followed by the bytes of the data frame. All data messages _from_ the client supply the microphone number as the voice number. Since for the time being we support exactly one microphone, the voice numbers in messages from the client are always zero. Size is 4 bytes plus the codec frame playload, typically 28 bytes for 11000bps.

See Also:
Constant Field Values

opcodeAggregatedData

public static final byte opcodeAggregatedData
An aggregated data packet contains a number of data packets. It starts with a standard header, and has an additional byte arg which is the number of data packets contained therein. The first contained data frame has a seqnum equal to the seqnum of the ggregated data packet, and are numbered sequentially thereafter. So the seqnum of the next packet after an aggregated data packet is larger by the number of data frames in the packet. Each data packet inside an aggregated data packet starts with a 1-byte length.

See Also:
Constant Field Values

opcodeLoginStatus

public static final byte opcodeLoginStatus
An opcode sent exclusively from the server to the client, and used only to support synchronization between voice bots and test clients. It contains the standard header plus the oid of the player whose login status has changed. The voiceNumber is 1 if it's a login, and 0 if it's a logout.

See Also:
Constant Field Values

opcodeChangeIgnoredStatus

public static final byte opcodeChangeIgnoredStatus
An opcode sent exclusively from the client to the server that marks a collection of oids as ignored or not ignored. The format is a short count of speakers whose ignore status should change, and for each speaker, a byte which is non-zero if it should be ignored or zero if it should no longer be ignored. This opcode is obsolete and unused; ignoredSpeakerOids are maintained via messaging with the proxy.

See Also:
Constant Field Values

opcodeHighest

public static final int opcodeHighest
See Also:
Constant Field Values

opcodeNames

public static String[] opcodeNames
Used in logging messages


voiceMsgSize

public static int[] voiceMsgSize
This gives the number of bytes in the message excluding the length, except for the data case, where it gives the number of bytes in the header, but not including the data itself


lengthBytes

public static int lengthBytes
There are two bytes in the length prefixed to a TCP message


speexNarrowBandFrameSize

public static int[] speexNarrowBandFrameSize
This array is indexed by Speex narrow-band mode, and gives the narrow-band frame size for that mode.


speexWideBandFrameSize

public static int[] speexWideBandFrameSize

maxVoiceChannels

public static int maxVoiceChannels
The server is supposed to run things so no client ever has more than this number of voice channels.


countLogger

private CountLogger countLogger
Counters that get logged every second


countPacketsIgnored

private static CountLogger.Counter countPacketsIgnored

countSeqNumGaps

private static CountLogger.Counter countSeqNumGaps

countSendLoginStatus

public static CountLogger.Counter countSendLoginStatus

countPacketsReceived

private static CountLogger.Counter countPacketsReceived

countDataFramesReceived

private static CountLogger.Counter countDataFramesReceived

countAllocateVoiceReceived

public static CountLogger.Counter countAllocateVoiceReceived

countDeallocateVoiceReceived

public static CountLogger.Counter countDeallocateVoiceReceived

countPacketsSent

private static CountLogger.Counter countPacketsSent

countDataFramesSent

private static CountLogger.Counter countDataFramesSent

countAllocateVoiceSent

public static CountLogger.Counter countAllocateVoiceSent

countDeallocateVoiceSent

public static CountLogger.Counter countDeallocateVoiceSent

runHistograms

public static boolean runHistograms

processPacketHistogram

public static TimeHistogram processPacketHistogram

dataSendHistogram

public static TimeHistogram dataSendHistogram

voiceAllocHistogram

public static TimeHistogram voiceAllocHistogram

voiceDeallocHistogram

public static TimeHistogram voiceDeallocHistogram

checkAuthToken

public static boolean checkAuthToken

conMgr

private VoicePlugin.VoiceConManager conMgr

voicePort

private Integer voicePort
The port number we're listening on


recordVoices

private boolean recordVoices
Should we record all voices as we run? ??? TBD: We'll need to make this more selective in the production version, via an API call


loginStatusEventReceivers

private Set<VoiceConnection> loginStatusEventReceivers
A map of connections that will receive login/logout events - - only used by the voice bot system.


loginStatusSeqNum

private short loginStatusSeqNum
The next sequence number for a login status message


clientTCPMessageIO

private ClientTCPMessageIO clientTCPMessageIO
The engine that handles TCP message traffic to all the clients.


createGroupWhenReferenced

protected static boolean createGroupWhenReferenced
If this is true, we'll synthesize the group and/or group member when an auth packet comes in. Used only for testing.


allowVoiceBots

protected static boolean allowVoiceBots
If this is true, we subscribe to login messages and pass on login notifications.


audibleRadius

private static float audibleRadius
Can hear positional sounds up to 20 meters away


hystericalMargin

protected static float hystericalMargin
The hysteresis constant: don't change whether a pair of positonal group members are in-radius of each other if the distance is within this distance of the audibleRadius.


instance

protected static VoicePlugin instance
singleton


serverVersion

private String serverVersion
The server version to send to clients


perceptionFilter

protected PerceptionFilter perceptionFilter

perceptionSubId

protected long perceptionSubId

updater

protected VoicePlugin.Updater updater

updaterThread

protected Thread updaterThread

running

protected boolean running

lock

protected transient Lock lock
Constructor Detail

VoicePlugin

public VoicePlugin()
The VoicePlugin accepts connections from game clients who have been supplied the IP and port number to contact by the initial game system login. The client initiates the connection, and must immediately thereafter send it's codec parameters. At that point, the client can send voice frames from the microphone, and the voice plugin forwards those frames to listeners. The process by which a set of listeners to any voice is established is game-dependent. But the sequence of events is fixed: - The listener allocates a "voice channel" to receive frames - The listener initializes the codec parameters for the new voice channel to be those associated with the channel. - As frames are received from clients, they are forwarded to listeners. At any point, for each client, there is a (possibly null) set of listeners; this is maintained in the voice group to which the player belongs.

Method Detail

handleVoiceProperties

private void handleVoiceProperties()
A method to encache the voice-specific members of multiverse.properties.


parseLongOrNull

private Long parseLongOrNull(String s)

getInstance

public static VoicePlugin getInstance()
Returns:
the VoicePlugin instance.

onActivate

public void onActivate()
Register the hooks and create the subscriptions for the VoicePlugin.

Overrides:
onActivate in class EnginePlugin

acceptConnection

public void acceptConnection(ClientConnection con)
The callback from ClientTCPIO invoked when a connection is established.

Specified by:
acceptConnection in interface ClientConnection.AcceptCallback
Parameters:
con - The ClientConnection object for the new connection.

sendLoginStatusToReceivers

protected void sendLoginStatusToReceivers(long playerOid,
                                          boolean login)
Used only when running voice bots.


getPlayerMember

protected GroupMember getPlayerMember(long playerOid)
Get the GroupMember associated with the playerOid, or null if there is none.

Parameters:
playerOid - The oid of the member returned.
Returns:
The member with the given playerOid.

processPacket

public void processPacket(ClientConnection con,
                          MVByteBuffer buf)
Process a packet received from a player.

Specified by:
processPacket in interface ClientConnection.MessageCallback
Parameters:
con - The VoiceConnection object of the player sending the packet.
buf - The buffer containing the packet. The buf limit is the size of the packet.

writeSpeexData

protected void writeSpeexData(BufferedOutputStream recordSpeexStream,
                              byte[] buf,
                              int startIndex,
                              int byteCount)
Write a single Speex frame to the stream, from the byte array

Parameters:
recordSpeexStream - The stream to which the voice frame(s) should be written.
buf - The buffer containing the voice frame(s).
startIndex - The index in the buf of the first byte to be written.
byteCount - The number of bytes of frame data to be written.

processAuthenticationPacket

public void processAuthenticationPacket(VoiceConnection playerCon,
                                        MVByteBuffer buf)
Check to see of the auth packet contains the proper credentials, and if so, create a group member in the specified group.

Parameters:
playerCon - The VoiceConnection object for the player that sent the auth packet.
buf - The buffer containing the auth packet.

initializeIgnoreList

protected void initializeIgnoreList(VoiceConnection playerCon)

trackNewPerceiver

protected void trackNewPerceiver(PositionalGroupMember member)
Internal method to add the positional group member to the set of member whose perceived players will be tracked.

Parameters:
member - The positional group member to be tracked.

processIgnoreListChangeMessage

protected void processIgnoreListChangeMessage(VoiceConnection playerCon,
                                              MVByteBuffer buf)
Change the ignored status of a set of potential speakers. Note that this is only called when processing an ignore request from a voice client, and that mechanism is now deprecated.

Parameters:
playerCon - The VoiceConnection object for the player that sent the blacklist packet.
buf - The buffer containing the blacklist message.

addToPerceptionFilter

protected void addToPerceptionFilter(long playerOid)
Internal method that adds the playerOid to the list of oids for which the perception filter will send perception messages.

Parameters:
playerOid - The oid of the player to be added to the perception filter.

removeFromPerceptionFilter

protected void removeFromPerceptionFilter(long playerOid)
Internal method that removes the playerOid from the list of oids for which the perception filter will send perception messages.

Parameters:
playerOid - The oid of the player to be removed to the perception filter.

removePlayerFromGroup

public void removePlayerFromGroup(VoiceConnection playerCon)
Remove the player identified by the argument from the group it belongs to.

Parameters:
playerCon - The VoiceConnection object corresponding to the player.

findVoiceGroup

protected VoiceGroup findVoiceGroup(long groupOid)
Return the group for groupOid, having checked to see that the group exists and contains the player.

Parameters:
groupOid - The oid of the group to be returned.

addGroup

public void addGroup(long groupOid,
                     VoiceGroup group)
Inform the VoicePlugin about the existance of a voice group.

Parameters:
groupOid - The oid of the voice group to be added.
group - The voice group to be added.

removeGroup

public void removeGroup(long groupOid)
Remove a group.

Parameters:
groupOid - The oid of the voice group to be removed.

sendPacketToListener

private void sendPacketToListener(VoiceConnection listener,
                                  MVByteBuffer buf)
Send a packet, whose contents is in the buf, to the listener.

Parameters:
listener - The VoiceConnection object for the listener.
buf - The buffer containing the packet to be sent.

sendAllocateVoice

public void sendAllocateVoice(VoiceConnection speaker,
                              VoiceConnection listener,
                              byte voiceNumber,
                              boolean positional)
Send an allocate voice packet to the listener, representing a voice channel from the speaker to the listener. This method is a required member of the VoiceSender interface.

Specified by:
sendAllocateVoice in interface VoiceSender
Parameters:
speaker - The VoiceConnection object for the speaker.
listener - The VoiceConnection object for the listener.
voiceNumber - The listener-specific number of the voice channel that is created by this allocation.
positional - If true, this voice channel is positional; if false, non-positional.

sendAllocateVoice

public void sendAllocateVoice(VoiceConnection speaker,
                              VoiceConnection listener,
                              byte voiceNumber,
                              byte opcode)
Send an allocate voice packet to the listener, representing a voice channel from the speaker to the listener. This method is a required member of the VoiceSender interface.

Specified by:
sendAllocateVoice in interface VoiceSender
Parameters:
speaker - The VoiceConnection object for the speaker.
listener - The VoiceConnection object for the listener.
voiceNumber - The listener-specific number of the voice channel that is created by this allocation.
opcode - The allocate opcode of the packet to be sent; there are three kinds of allocate packets, each with different opcodes, but at this time, only opcodeAllocateCodec is ever sent.

sendDeallocateVoice

public void sendDeallocateVoice(VoiceConnection speaker,
                                VoiceConnection listener,
                                byte voiceNumber)
Send a message to the connection deallocating the voice with the given number.

Specified by:
sendDeallocateVoice in interface VoiceSender
Parameters:
speaker - The VoiceConnection object for the speaker.
listener - The VoiceConnection object for the listener.
voiceNumber - The listener-specific number of the voice channel that is removed by this deallocation.

sendVoiceFrame

public void sendVoiceFrame(VoiceConnection speaker,
                           VoiceConnection listener,
                           byte opcode,
                           byte voiceNumber,
                           MVByteBuffer sourceBuf,
                           short pktLength)
Send a message containing voice frame(s) to the listener.

Specified by:
sendVoiceFrame in interface VoiceSender
Parameters:
speaker - The VoiceConnection object for the speaker.
listener - The VoiceConnection object for the listener.
opcode - The opcode of the voice frame(s) packet. There are two possible opcodes: opcodeData, which sends a single frame, and opcodeAggregatedData, which sends multiple voice frames.
voiceNumber - The listener-specific number of the voice channel that is removed by this deallocation.
sourceBuf - The buffer containing the voice frame(s).
pktLength - The number of bytes in the buffer.

sendLoginStatus

public void sendLoginStatus(VoiceConnection receiver,
                            long playerOid,
                            boolean login)
Send a login status message, telling the receiver that a player has logged in. This is used only for voice bots.

Parameters:
receiver - The VoiceConnection object for the voice bot manager to receive the packet.
playerOid - The oid of the player whose login status changed.
login - If true, the playerOid logged in; if false, the playerOid logged out.

sendExtensionMessage

public void sendExtensionMessage(WorldManagerClient.ExtensionMessage msg)
Send an ExtensionMessage.

Specified by:
sendExtensionMessage in interface VoiceSender
Parameters:
msg - The ExtensionMessage to be sent.

openSpeexVoiceFile

protected BufferedOutputStream openSpeexVoiceFile(long oid)
Internal method used when writing Speex voice files. This is used only for testing.

Parameters:
oid - The oid used to look up the voice file.
Returns:
The stream object representing the opened and writable file.

getConnectionData

public VoiceConnection getConnectionData(ClientConnection con)
Get the VoiceConnection object associated with the ClientConnection. con The ClientConnection object.

Parameters:
con - The ClientConnection object whose VoiceConnection should be returned.
Returns:
The VoiceConnection object associated with the ClientConnection.

formatCon

public String formatCon(ClientConnection con)
Produce a string description of the ClientConnection object.

Parameters:
con - The ClientConnection object whose description is to be returned.
Returns:
The string description of the ClientConnection object.

connectionReset

public void connectionReset(ClientConnection con)
In response to a ClientConnection being closed, deallocate all voices in use by the connection, and remove the listeners, and close record stream if it's open.

Specified by:
connectionReset in interface ClientConnection.MessageCallback
Parameters:
con - The ClientConnection object that was closed.

expungeVoiceClient

protected void expungeVoiceClient(long playerOid)
Remove the voice client associated with the playerOid from the VoicePlugin data structures.

Parameters:
playerOid - The oid of the player being expunged.

expungeVoiceClient

protected void expungeVoiceClient(long playerOid,
                                  VoiceConnection con)
Remove the voice client associated with the playerOid from the VoicePlugin data structures.

Parameters:
playerOid - The oid of the player being expunged.
con - The VoiceConnection object for the player.

incSeqNum

public static short incSeqNum(short original)
Increment the short seqNum so that it wraps around properly.

Parameters:
original - The seqNum before being incremented.
Returns:
The incremented seqNum.

incSeqNum

public static short incSeqNum(short original,
                              int byWhat)
Increment the short seqNum so that it wraps around properly.

Parameters:
original - The seqNum before being incremented.
byWhat - The amount to increment the seqNum by.
Returns:
The incremented seqNum.

encodedFrameSizeForMode

public static int encodedFrameSizeForMode(int mode,
                                          boolean wideBand)
Return the total frame size for narrow or wide-band mode given

Parameters:
mode - The Speex mode number for the frame.
wideBand - If true, the frame is wide-band; if false, narrow-band.
Returns:
The frame size.

encodedFrameSizeFromFirstByte

public static int encodedFrameSizeFromFirstByte(byte b)
Return the frame size for the band/mode specified by the first byte of the Speex frame.

Parameters:
b - The first byte of the Speex frame.
Returns:
The frame size.

opcodeString

public static String opcodeString(byte opcode)
Return a string representation of the opcode number; used for logging.

Parameters:
opcode - The voice packet opcode.
Returns:
The string representing the opcode.