Acme-MUDLike
view release on metacpan or search on metacpan
lib/Acme/MUDLike.pm view on Meta::CPAN
$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 $request = shift;
# this is called by login() immediately after verifying credientials
if($request->request->url->path =~ m/pushstream/) {
# warn "pushstream path_session handling XXX";
my $w = Coro::Event->var(var => \$got_message, poll => 'w');
while(1) {
$w->next;
# warn "got_message diddled XXX";
# on submitting the form without a JS background post, the poll HTTP connection gets broken
$SIG{PIPE} = 'IGNORE';
$request->print( join "<br>\n", map { s{<}{\<}gs; s{\n}{<br>\n}g; $_ } $self->get_messages );
$request->next;
}
}
if($request->request->url->path =~ m/sendmessage/) {
while(1) {
# warn "sendmessage path_session handling XXX";
my $msg = $request->param('message');
$self->parse_command($msg);
# $request->print("Got message.\n");
$request->print($self->get_html_messages());
$request->next;
}
}
#
# players get three execution contexts:
# * one for AJAX message posts without header/footer in the reply
# * one for COMET message pulls
# * the main HTML one below (which might only run once); arbitrarily selected as being the main one cuz its longest
#
$floor->insert($self);
while(1) {
$request->print(header);
lib/Acme/MUDLike.pm view on Meta::CPAN
# chat messages first so they appear in the log below
# there's only one action defined right now -- chat. everything else hangs off of that.
my $msg = $request->param('message');
$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
}
sub parse_command {
my $self = shift;
my $msg = shift;
warn "parse_command: msg: ``$msg''";
$self->tell_object("> $msg");
if($msg and $msg =~ m{^/}) {
my @args = split / /, $msg;
(my $cmd) = shift(@args) =~ m{/(\w+)};
# XXX I'd like to see template matching, like V N A N, then preact/act/postact
if( $self->can("_$cmd") ) {
eval { $self->can("_$cmd")->($self, @args); 1; } or $self->tell_object("Error in command: ``$@''.");
} else {
$self->tell_object("No such command: $cmd.");
}
} elsif($msg) {
$floor->tell_object($self->name . ': ' . $msg); # XXX should be $self->environment->tell_object
# $request->print("Got it!\n");
}
}
lib/Acme/MUDLike.pm view on Meta::CPAN
},
getIfModified: function( url, data, callback, type ) {
return jQuery.get(url, data, callback, type, 1);
},
getScript: function( url, callback ) {
return jQuery.get(url, null, callback, "script");
},
getJSON: function( url, data, callback ) {
return jQuery.get(url, data, callback, "json");
},
post: function( url, data, callback, type ) {
if ( jQuery.isFunction( data ) ) {
callback = data;
data = {};
}
return jQuery.ajax({
type: "POST",
url: url,
data: data,
success: callback,
lib/Acme/MUDLike.pm view on Meta::CPAN
// if data available
if ( s.data ) {
// convert data if not already a string
if (s.processData && typeof s.data != "string")
s.data = jQuery.param(s.data);
// append data to url for get requests
if( s.type.toLowerCase() == "get" ) {
// "?" + data or "&" + data (in case there are already params)
s.url += ((s.url.indexOf("?") > -1) ? "&" : "?") + s.data;
// IE likes to send both get and post data, prevent this
s.data = null;
}
}
// Watch for a new set of requests
if ( s.global && ! jQuery.active++ )
jQuery.event.trigger( "ajaxStart" );
var requestDone = false;
( run in 0.550 second using v1.01-cache-2.11-cpan-ceb78f64989 )