Games-Axmud
view release on metacpan or search on metacpan
lib/Games/Axmud/Client.pm view on Meta::CPAN
}
# Check the session's connection status
if ($otherSession->status ne 'disconnected' && $otherSession->status ne 'offline') {
return undef;
}
# Check GA::Session file objects
foreach my $fileObj ($otherSession->ivValues('sessionFileObjHash')) {
if ($fileObj->modifyFlag) {
return undef;
}
}
}
# There are no connected sessions or unsaved files
return 1;
}
sub broadcastInstruct {
# Can be called by anything (with great caution!)
# Executes an instruction in every session (optionally, with the exception of a specified
# session)
#
# Expected arguments
# $instruct - The instruction to execute, e.g. 'north', ';about'
#
# Optional arguments
# $excludeSession - The GA::Session to which the instruction should NOT be executed.
# If 'undef', the instruction is executed in every session
#
# Return values
# 'undef' on improper arguments
# 1 otherwise
my ($self, $instruct, $excludeSession, $check) = @_;
# Check for improper arguments
if (! defined $instruct || defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->broadcastInstruct', @_);
}
foreach my $session ($self->listSessions()) {
if (! $excludeSession || ($excludeSession ne $session)) {
$session->doInstruct($instruct);
}
}
return 1;
}
# Buffers
sub updateInstructBuffer {
# Called by GA::Session->updateInstructBuffer when an instruction is added to the session's
# buffer registry
# Updates this client's own instruction buffer, creating a separate buffer object (with a
# different ->number than the one created by the calling function)
#
# Expected arguments
# $session - The calling GA::Session
# $instruct - The instruction itself (e.g. ';setworld deathmud' or 'north;kill orc')
# $type - The type of instruction: 'client' for a client command, 'world' for a
# world command, 'perl' for a Perl command and 'echo' for an echo command
#
# Return values
# 'undef' on improper arguments or if the buffer is not updated
# Otherwise returns the buffer object created
my ($self, $session, $instruct, $type, $check) = @_;
# Local variables
my $obj;
# Check for improper arguments
if (! defined $session || ! defined $instruct || ! defined $type || defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->updateInstructBuffer', @_);
}
if (! defined $self->instructBufferFirst) {
# This the first instruction ever processed
$self->ivPoke('instructBufferFirst', 0);
}
# Create a new buffer object for this instruction
$obj = Games::Axmud::Buffer::Instruct->new(
$session,
'client',
$self->instructBufferCount,
$instruct,
$type,
$self->clientTime,
);
if (! $obj) {
return undef;
} else {
# Update the instruction buffer
$self->ivAdd('instructBufferHash', $obj->number, $obj);
$self->ivIncrement('instructBufferCount');
$self->ivPoke('instructBufferLast', ($self->instructBufferCount - 1));
# If the buffer is full, remove the oldest line
if ($self->instructBufferCount > $self->customInstructBufferSize) {
$self->ivDelete('instructBufferHash', $self->instructBufferFirst);
$self->ivIncrement('instructBufferFirst');
}
return $obj;
}
}
sub updateCmdBuffer {
# Called by GA::Session->updateCmdBuffer when a world command is added to the session's
# buffer registry
# Updates this client's own world command buffer, creating a separate buffer object (with a
# different ->number than the one created by the calling function)
#
# Expected arguments
# $session - The calling GA::Session
# $cmd - The world command itself (e.g. 'north', 'kill orc')
#
# Return values
# 'undef' on improper arguments or if the buffer can't be updated
# Otherwise returns the buffer object created
my ($self, $session, $cmd, $check) = @_;
# Local variables
my $obj;
# Check for improper arguments
if (! defined $session || ! defined $cmd || defined $check) {
return $axmud::CLIENT->writeImproper($self->_objClass . '->updateCmdBuffer', @_);
}
if (! defined $self->cmdBufferFirst) {
# This the first world command ever processed
$self->ivPoke('cmdBufferFirst', 0);
}
# Create a new buffer object for this world command
$obj = Games::Axmud::Buffer::Cmd->new(
$session,
'client',
$self->cmdBufferCount,
$cmd,
$self->clientTime,
);
if (! $obj) {
return undef;
} else {
# Update the world command buffer
$self->ivAdd('cmdBufferHash', $obj->number, $obj);
$self->ivIncrement('cmdBufferCount');
$self->ivPoke('cmdBufferLast', ($self->cmdBufferCount - 1));
# If the buffer is full, remove the oldest line
if ($self->cmdBufferCount > $self->customCmdBufferSize) {
$self->ivDelete('cmdBufferHash', $self->cmdBufferFirst);
$self->ivIncrement('cmdBufferFirst');
}
return $obj;
}
( run in 1.046 second using v1.01-cache-2.11-cpan-39bf76dae61 )