A TCP/IP pluggin compatible with AGS 3.x.x

Started by JpSoft, Fri 04/07/2008 16:28:56

Previous topic - Next topic

Dualnames

Well, I'm using AGS 3.02.. that must be it then, well here's the game files if scotch woud like to check em out, if it's not the version of the AGS that's causing the plug-in to not be loaded..

http://ledzepforever.googlepages.com/hhgtags.rar
Worked on Strangeland, Primordia, Hob's Barrow, The Cat Lady, Mage's Initiation, Until I Have You, Downfall, Hunie Pop, and every game in the Wadjet Eye Games catalogue (porting)

SSH

#21
Shouldn't SocketServer* Create(); be static? I can't seem to create a socket server...


Also, it would be great if there was a way to pull the user's standard proxy server settings out of the control panel. I've seen other programs do this, so there must be a way.

Here's a little example to let users get their IP addresses in plain text:

       cs.Write("GET /simple/ HTTP/1.1\r\n");
        cs.Write("Host: www.showmyip.com\r\n");
          cs.Write("\r\n");

Then poll as in scotch's example
12

scotch

Yeah SocketServer doesn't work in that release. I have no idea about proxies... outside of having to use a HTTP one at school. If someone explains how that all works I'll be happy to implement it.

I don't know why it won't work for you dualnames but I'll look into it.

GarageGothic

Why do I have the feeling that SSH will eventually turn his hypertext module into an AGS based web browser?   ;)

Great work, scotch! I'm already considering possible uses for the plugin.

SSH

Any chance you could post your IRC client code (or PM it to me), scotch? no point re-inventing the wheel, after all...
12

scotch

#25
Well it's not much of a client... it doesn't even respond to PINGs, but here

Code: ags
// room script file

Socket* irc;
String chan;
function room_AfterFadeIn()
{
  chan = "#ags";
  irc = Socket.Create();
  irc.Open("irc.adventuregamestudio.co.uk", 6667);
  irc.Write("NICK ags_sock
");
  irc.Write("USER socky socky socky :ags_sock puppet
");
  irc.Flush();
  Wait(80);
  irc.Write("JOIN ");
  irc.Write(chan); irc.Write("
");
  irc.Flush();
}


function room_RepExec()
{
  if(irc != null) irc.Poll();
 if(irc!=null && irc.ToRead()) {
  String line = irc.Read();
  if(line.Contains("PRIVMSG")==-1) return;
  int msgstrt = line.Contains(" :")+2;
  int nameEnd = line.Contains("!");
  if(msgstrt == -1 || nameEnd == -1) return;
  String prefix = line.Substring(1, nameEnd);
  prefix = prefix.Append(": ");
  
  cEgo.Say(prefix.Append(line.Substring(msgstrt, line.Length-msgstrt-2)));
 }
}
function hHotspot1_Interact()
{
  if(irc) {
    String msg = Game.InputBox("What do you want to say?");
    irc.Write("PRIVMSG ");
    irc.Write(chan);
    irc.Write(" :");
    irc.Write(msg);
    irc.Write("
");
    irc.Flush();
    }
}

magintz

I made a little server proxy in C at the beginning of the year. I didn't code everything myself as I was mainly focused on process queues and threads, but I'll see if I have anything that might be helpful.

My code initially ran by creating a passive socket on the desired port, this would act as a the servers incoming port; to send stuff out you create an active socket a little later.

The passive socket basically needs to open the socket and wait for a client to attempt to access it; thus accepting the connection and binding that clients address to the socket.

It then needs to read in the data from the passive socket sent by the client and commit a reply, perhaps a text response saying packet received or whatever. But it needs to do this over the active socket, which most know a host name and port number.  You need to verify that the host exists and open a socket to the address.

I have no idea if this helps, like I said this was done at the beginning of the year and I was only really focused on processor queues so I used a lot of libraries and such.
When I was a little kid we had a sand box. It was a quicksand box. I was an only child... eventually.

Pumaman

Quote from: SSH on Wed 09/07/2008 14:11:09
Also, it would be great if there was a way to pull the user's standard proxy server settings out of the control panel. I've seen other programs do this, so there must be a way.

Most programs use the WinINet API:
http://msdn.microsoft.com/en-us/library/aa385096(VS.85).aspx
which automatically uses the IE proxy settings. However this is a different API to the Sockets API which this plugin is using, so I don't think it's feasible to combine the two.

magintz

In case anyone is interested a few weeks ago I got a little client/server relationship working.  This code isn't perfect but should get people started.

Code: ags

// room script file
Socket* client;
SocketServer* server;
String hostname;
int portno;

function room_AfterFadeIn()
{
  // Always connect through port 12345(consistency)
  portno = 12345;
    
  // Ask the user if they want to host or join
  String msg = Game.InputBox("-host or -join");
  
  // If joining
  if(msg == "-join") {
    // Ask host address to connect to
    hostname = Game.InputBox("Please enter the host address");
    
    client = Socket.Create();
    
    // Open the connection
    if(client.Open(hostname, portno)) {
      cEgo.Say("Connection opened");
    }
    else cEgo.Say("Connection failed");
  }

 // If hosting
  else if(msg == "-host") {
    server = SocketServer.Create();
    client = null;
    
    server.Listen(portno);  // Begin listening for connections
    
    // While not connected to a client
    while(client == null) {
      client = server.GetNewSocket();
      cEgo.Say("Waiting for a connection...");
    }
  }

  else cEgo.Say("Invalid Command");
}

function room_RepExec()
{
  // always listen for messages while the connection is open
  if(client != null) client.Poll();
  
// If a message is received read it and sayit
  if(client!=null && client.ToRead()) {
    String line = client.Read();
      
    cEgo.Say(line);
  }
}


I'm sure people can improve this or modify it to do whatever they want.
When I was a little kid we had a sand box. It was a quicksand box. I was an only child... eventually.

Anomaly

Has anyone gotten this up and running smoothly?

I was just imagining how cool turn-based cooperative gaming would be Lucas/Sierra style.

or heck.. just a few rooms of tcp/ip chatting.  mmorpg lucas/sierra style.

-
"The room is bright. 
You are likely to be vomited upon by a Shrunk."

Trent R

Quote from: Anomaly on Sat 29/11/2008 13:40:57mmorpg lucas/sierra style.
Eww. But, each to his own.

And to be ontopic, this looks totally awesome (I happened across it a few months ago and read through it)

~Trent
To give back to the AGS community, I can get you free, full versions of commercial software. Recently, Paint Shop Pro X, and eXPert PDF Pro 6. Please PM me for details.


Current Project: The Wanderer
On Hold: Hero of the Rune

magintz

What would be handy (I might have a go at this) is to create some uniform protocol for talk, give etc... so players can interact and not get commands mixed up with messages such as.

A communication between two different versions of the same game, using string manipulation to get the contents between the XML tags. (Does AGS have an XML parser?)

Sent from A to B:

<say="a">Hello<\say>
<give="b">Apple<\give>

Character A would say Hello on B's screen.
Player A would lose the apple and give it to player B.

The ="a" part is used to let the other player know which of many possible characters should say/receive said item, which could be handy if player A were to give an item to an NPC which would later be needed by player B.

Thoughts, suggestions?
When I was a little kid we had a sand box. It was a quicksand box. I was an only child... eventually.

naltimari

Quote from: magintz on Mon 01/12/2008 18:16:14
A communication between two different versions of the same game, using string manipulation to get the contents between the XML tags. (Does AGS have an XML parser?)

XML is not a great idea, and the reason is twofold: it imposes messaging overhead, which is bad for latency-sensitive networking protocols (such as game stuff, like object or character positions, as well as game state), and it also imposes XML parsing on the client side. And, last but not least, any human-readable protocol can easily be 'hacked'.

I think a binary protocol is more suited. Having said that, a high-level AGS module could handle the message passing and state maintenance, using the TCP-IP plugin as a framework.

SMF spam blocked by CleanTalk