Acme-MUDLike
view release on metacpan or search on metacpan
lib/Acme/MUDLike.pm view on Meta::CPAN
# * eval, call
#
# * inventory's insert() method should set the insertee's environment to itself. that way, all objects have an environment.
#
# * Commands need to do $floor->tell_object or $self->tell_object rather than output directly.
#
# * Put @messages into the room ($floor). Get the chat action out of the main loop. Dispatch all
# actions. Maybe.
#
our $password; # Acme::State friendly
our $floor; # holds all other objects
our $players; # holds all players; kind of like $floor except in the future, inactive players might get removed from the floor, or there might be multiple rooms
my $continuity;
my $got_message; # diddled to wake the chat event watchers
$SIG{PIPE} = 'IGNORE';
sub new {
my $package = shift;
my %args = @_;
die "We've already got one" if $continuity;
$password = delete $args{password} if exists $args{password};
$password ||= join('', map { $_->[int rand scalar @$_] } (['a'..'z', 'A'..'Z', '0'..'9']) x 8),
my $staticp = sub {
# warn "staticp: url->path: ``@{[ $_[0]->url->path ]}''";
return 0 if $_[0]->url->path =~ m/\.js$/;
# warn "staticp: dynamic js handling override not engaged";
return $_[0]->url->path =~ m/\.(jpg|jpeg|gif|png|css|ico|js)$/
};
$continuity = $args{continuity} || Continuity->new(
staticp => sub { $staticp->(@_); },
callback => sub { login(@_) },
path_session => 1,
port => 2000,
%args,
);
print "Admin:\n", $continuity->adapter->daemon->url, '?admin=', $password, '&nick=', (getpwuid $<)[0], "\n";
$floor ||= Acme::MUDLike::room->new();
$players ||= Acme::MUDLike::inventory->new();
bless { }, $package;
}
sub loop { my $self = shift; $continuity->loop(@_); }
sub header {
lib/Acme/MUDLike.pm view on Meta::CPAN
return;
}
#
# login
#
while(1) {
my $nick_tmp = $request->param('nick');
my $admin_tmp = $request->param('admin');
if(defined($nick_tmp) and defined($admin_tmp) and $nick_tmp =~ m/^[a-z]{2,20}$/i and $admin_tmp eq $password) {
my $nick = $nick_tmp;
$player = $players->named($nick) || $players->insert(Acme::MUDLike::player->new(name => $nick), );
$player->request = $request;
# @_ = ($player, $request,); goto &{Acme::MUDLike::player->can('command')};
$player->command($request); # doesn't return
}
# warn "trying login again XXX";
$nick_tmp ||= ''; $admin_tmp ||= '';
$nick_tmp =~ s/[^a-z]//gi; $admin_tmp =~ s/[^a-z0-9]//gi;
$request->print(
header, # $msg,
qq{
<form method="post" action="/">
<input type="text" name="nick" value="$nick_tmp"> <-- nickname<br>
<input type="password" name="admin" value="$admin_tmp"> <-- admin password<br>
<input type="submit" value="Enter"><br>
</form>
},
footer,
);
$request->next();
}
}
lib/Acme/MUDLike.pm view on Meta::CPAN
my $pack = shift;
bless {
inventory => Acme::MUDLike::inventory->new,
messages => [ ],
@_,
}, $pack;
}
sub request :lvalue { $_[0]->{request} }
sub id { $_[0]->{name} eq $_[1] or $_[0] eq $_[1] }
sub name { $_[0]->{name} }
sub password { $_[0]->{password} }
sub x :lvalue { $_[0]->{x} }
sub y :lvalue { $_[0]->{y} }
sub xy { $_[0]->{x}, $_[0]->{y} }
sub get { 0; } # can't be picked up
sub inventory { $_[0]->{inventory} }
sub evalcode :lvalue { $_[0]->{evalcode } }
sub current_item :lvalue { $_[0]->{current_item} }
sub tell_object {
my $self = shift;
lib/Acme/MUDLike.pm view on Meta::CPAN
$self->parse_command($msg);
};
do {
$request->print(qq{
<b>Chat/Command:</b>
<form method="post" id="f" action="/">
<input type="hidden" name="action" value="chat">
<input type="hidden" id="nick" name="nick" value="@{[ $self->name ]}">
<input type="hidden" id="admin" name="admin" value="$password">
<input type="text" id="message" name="message" size="50">
<!-- <input type="submit" name="sendbutton" value="Send" id="sendbutton"> -->
<input type="submit" name="sendbutton" value="Send" id="sendbutton">
<span id="status"></span>
</form>
<br>
<div id="log">@{[ $self->get_html_messages ]}</div>
});
};
lib/Acme/MUDLike.pm view on Meta::CPAN
Optional. Pass in an existing L<Continuity> instance.
Must have been created with the parameter C<< path_session => 1 >>.
=item C<port>
Optional. Defaults to C<2000>.
This and other parameters, such as those documented in L<Continuity>, are passed through
to C<< Continuity->new() >>.
=item C<password>
Optional. Password to use.
Everyone gets the same password, and anyone with the password can log in with any name.
Otherwise one is pseudo-randomly generated and printed to C<stdout>.
=cut
=head1 HISTORY
=over 8
=item 0.01
lib/Acme/MUDLike.pm view on Meta::CPAN
enabled: "!a.disabled",
disabled: "a.disabled",
checked: "a.checked",
selected: "a.selected||jQuery.attr(a,'selected')",
// Form elements
text: "a.type=='text'",
radio: "a.type=='radio'",
checkbox: "a.type=='checkbox'",
file: "a.type=='file'",
password: "a.type=='password'",
submit: "a.type=='submit'",
image: "a.type=='image'",
reset: "a.type=='reset'",
button: 'a.type=="button"||jQuery.nodeName(a,"button")',
input: "/input|select|textarea|button/i.test(a.nodeName)"
},
".": "jQuery.className.has(a,m[2])",
"@": {
"=": "z==m[4]",
"!=": "z!=m[4]",
( run in 0.690 second using v1.01-cache-2.11-cpan-49f99fa48dc )