View previous topic :: View next topic |
Author |
Message |
ExileStrife
Joined: 14 Mar 2008 Posts: 21
|
Posted: Fri Mar 14, 2008 23:56 Post subject: What is MNX capable of? |
|
|
I was cleaning out our server directory and updating some NWNX stuff and noticed nwnx_mnx.so and realized I had no idea what that was there for. I could barely find any information for it on the forums, but it seems like it is capable of opening a UDP socket and sending packets to a listening ports.
For starters, are there any demos of this functionality being demonstrated? Secondly, however, is it also possible for MNX to listen on a certain port? One could make some very useful utilities for polling NWN and receiving information through a UDP stream that any type of client could intercept. |
|
Back to top |
|
|
PlasmaJohn
Joined: 04 Mar 2005 Posts: 70 Location: The Garage
|
Posted: Tue Mar 25, 2008 15:53 Post subject: |
|
|
Quote: | ... are there any demos of this functionality being demonstrated? |
As you've seen, MNX will send a UDP request to the configured host and port. It will also wait for a response. This is useful if you need some heavy computation performed outside of the game server. It's also easier (IMO ) to produce a network server than it is to write an NWNX plugin.
At the end of this post I've inlined the example perl script that came with the original Linux source of the plugin. It listens on port 2182 for a request. It doesn't care what was sent to it, it just responds with the date. (Or a line from the fortune file if your system has that toy and you swap the commenting around).
Quote: | ... is it also possible for MNX to listen on a certain port? |
Anything is possible given infinite time and resources
While adding serverlike functionality to MNX is possible, it's possible in the sense of adding it to any other unrelated (non-networking) plugin. In other words, it makes more sense to write it as a seperate plugin.
MNX responds to events from the Script VM, sends a request and gets a response and returns to the VM. A server needs to respond to external events. Unforutnately it cannot do this within the VM thread safely, so it needs its own thread. Not a big deal if you're careful.
Code: | #!/usr/bin/perl -w
use strict;
# mnx.pl - backend for Minimal NWNX
#
# shamelessly based on Cookbook ex.17-2, udpquotd.pl
#
# listens for requests on udp 1820
use IO::Socket;
use vars qw/$sock $inpkt $outpkt $hisaddr $hishost $PORTNO $CMDLINE/;
$PORTNO = 2182;
# $CMDLINE = '/usr/games/fortune -s';
$CMDLINE = 'date';
sub pktdump($) {
my ($pkt) = @_;
my ($chrout,$length, $i,$j);
$length= length($pkt);
for($j=0; $j<$length; ) {
$chrout = " ";
for($i=0; $i<16 && $j<$length; ++$i ) {
my $hexval = ord(substr($pkt,$j,1));
my $hexstr = pack('H*',$hexval);
printf(" %02x",$hexval);
substr($chrout,$i,1) = ($hexval>31 && $hexval<128)?chr($hexval):".";
++$j;
}
while($i<16) {
print " ";
++$i;
}
print " - $chrout\n";
}
}
$sock = IO::Socket::INET->new(LocalPort => $PORTNO, Proto => 'udp')
or die "socket: $@";
print "Listening to UDP$PORTNO\n";
while($sock->recv($inpkt,1024)) {
my ($port, $ipaddr) = sockaddr_in($sock->peername);
# my ($nwnx,$op,$arg,$value) = split(/[!]/,$inpkt,4);
# print "Received $op $arg from " . inet_ntoa($ipaddr) . ":$port\n";
print "Received $inpkt from " . inet_ntoa($ipaddr) . ":$port\n";
my $output = `$CMDLINE`; # . "¬";
print "$output\n";
$sock->send($output);
}
die "recv: $!";
|
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|