Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / AGK 2.0 network protocol wrapper?

Author
Message
sovr
14
Years of Service
User Offline
Joined: 2nd Jan 2010
Location: USA
Posted: 1st Feb 2014 23:03
Hello everyone! I have been working with some java applications and was wanting to connect them to my agk projects through the network. Does anyone know what the AppGameKit protocol wrapper looks like, or do I just have to set a port and see what comes through? Thank you in advance

website: http://worksimpleintelligen.wix.com/parkers-apps
facebook: https://www.facebook.com/ParkersApps
youtube: http://www.youtube.com/user/mrsovr
Markus
Valued Member
20
Years of Service
User Offline
Joined: 10th Apr 2004
Location: Germany
Posted: 2nd Feb 2014 09:08
i believe its tcp, but agk have no raw data transfer because it use
the multiplayer commands.
without help from agk team, its best you look at traffic between
two agk apps. the current agk need the struct from Send/Get NetworkMessage Command.

here is a easy test example:
http://www.appgamekit.com/documentation/examples/multiplayer/0_getting_started.htm

AGK 108 (B)19 : Windows 8.1 Pro 64 Bit : AMD Radeon HD 6670
Grayvyn
15
Years of Service
User Offline
Joined: 30th Oct 2008
Location: Southern California
Posted: 4th Feb 2014 17:58
Here is what TGC has posted and helped me make a C# server connect to a Tier 1 client.

http://forum.thegamecreators.com/?m=forum_view&t=195872&b=41

I didn't implement everything in it but what I needed. It also has a problem where if the server sends too much data to the client, the client drops the connection. Never figured it out. I just slowed the server down and it's been ok. Here is my game post and it is up and running to play.

http://forum.thegamecreators.com/?m=forum_view&t=207369&b=48

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 5th Jan 2015 09:58
Very late bump...Has anyone got a working example of AppGameKit -> C#?

I've looked at the pseudo code in the other thread, but as a newbie to UDP/TCP in C#, I'm starting at the absolute beginning.

Quidquid latine dictum sit, altum sonatur
Grayvyn
15
Years of Service
User Offline
Joined: 30th Oct 2008
Location: Southern California
Posted: 5th Jan 2015 18:51
Yes, I have a C# server and a AGK1/2 client working. Uuuummm, let me see if I can post my C# code for the network today sometime...

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 5th Jan 2015 19:43
That's fantastic news

I was about to start working with this tutorial to try and recreate it. I don't know how successful I would have been.

Quidquid latine dictum sit, altum sonatur
Grayvyn
15
Years of Service
User Offline
Joined: 30th Oct 2008
Location: Southern California
Posted: 5th Jan 2015 22:21
OK, here is the C# code in a huge mess. It isn't all of my packet processing code since the send and recv of packets the same for most.

The major problem I had AFTER I got this working was making it thread safe with my main GUI thread and background world processing threads. I still get odd crashes when ppl log in from time to time.

Here is a link to the client launcher:
http://www.rpgwo.com/download/RPGWO5Launcher.zip
The server is up as of this post and "should" stay up.
Oh, this is my 2D Fantasy, Sandbox, Online RPG that I have stopped working on for now. I am currently working on a Party-based, Online RPG inspired by 80's single player RPGs. I'll announce it some year.



BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 5th Jan 2015 22:26
Thank you for sharing, it is hugely appreciated!

I will be sharing my efforts later in the form of a tutorial, I have interesting plans for this method...if I succeed in making it work.

Quidquid latine dictum sit, altum sonatur
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 6th Jan 2015 17:29
I've imported into Visual Studio, and there's some elements missing that I can't guess at recreating...

PacketResult
PacketResultEnum
PacketVersion

Are these available in a another class somewhere? Googling didn't find a standard class for these.

Quidquid latine dictum sit, altum sonatur
Grayvyn
15
Years of Service
User Offline
Joined: 30th Oct 2008
Location: Southern California
Posted: 6th Jan 2015 18:44
Here it is. It is my code.



BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 7th Jan 2015 18:14
Thanks again

I have the code in place, and I've commented out a few things to get it up and running. I'm assuming:

Game.flgUpdateClientList = true;

is returning a flag to the main game class, to tell it that the players have changed (New/Removed).

EventProcess.Add(EventClass.EventEnum.Event_LeaveWorld, 0, Client[cIndex].PartyIndex, 0, 0, 0)

is a class that receives all of the messages and are then processed according to their content. (Maybe I need this class for it to make sense?)


Now, I'm trying to get the server up and running, but I'm not entirely sure how I do it. I've created a Net object (I've called it AGKNet instead of Net):

agkNet = new AGKNet();

I assume the next step is to call SetupNet(), but this is a static method so I'm not sure how I call it?

public static void SetupNet()

The closest I have is this, but it doesn't like SetupNet as the initiating method. In this case I haven't created an oibject, I'm treating AGKNet as static:

AGKthread = new System.Threading.Thread(new System.Threading.ThreadStart(AGKNet.SetupNet()));


help, in capital letters :0

My next assumption is that once this thread is alive, it will look after itself and keep accepting incoming connections and messages?

Quidquid latine dictum sit, altum sonatur
Grayvyn
15
Years of Service
User Offline
Joined: 30th Oct 2008
Location: Southern California
Posted: 7th Jan 2015 20:24
Just call AGKNet.SetupNet(); in your main form thread, like Form1_Load(). You don't need to create an AGKNet object.

I make most of my code/classes static cuz they generally are declared once. Static stuff doesn't respond to the "new" keyword, I believe.

mainSocket.BeginAccept() starts its own thread and callback. That why you need to be careful of the threads walking on each other if the incoming packets affect game data... which they do of course.

The EventProcess object is my thread safe event queue that the network feeds. The main game thread processes the events in there, like move player or attack monster. I tried to make sure only the main game thread touches world data.

When closing the server program, call AGKNet.Close() and it should clean up the net thread and resources.

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 8th Jan 2015 16:36 Edited at: 8th Jan 2015 16:39
I'm getting there slowly, thanks again for the help.

1. I call AGKNet.setupNet() and I get a network

2. I can call AGKNet.Close() and close it successfully
(I had to add a check in OnClientConnect, this gets a rogue call on Close() so I ignore it)

3. I can JoinNetwork() from AGK. AppGameKit reports a successful connection. C# reports a new client

4. I can send a message that is a simple string ("test") to the C# server, and it is received as a packet type 4. I haven't tried to decipher it yet, just happy that it is sending and receiving.

4. In C# I then try to

AGKNet.Client[0].Send("test");

I have created a Send() method that accepts a string and converts to bytes[] before calling your original Send(bytes[] ,length). I get a byte array of 8 bytes, 2 bytes per char. It is happy that Client[0] is available (I changed your base 1 to base 0 when creating clients) In AGK:

getNetworkMessage(NetID)

never sees the message.
This is all running on one PC using address 127.0.0.1

Any ideas where I am going wrong with the Send from C#?

Quidquid latine dictum sit, altum sonatur
Grayvyn
15
Years of Service
User Offline
Joined: 30th Oct 2008
Location: Southern California
Posted: 8th Jan 2015 17:38
Hmm, make sure you are sending the AppGameKit header with your string data.

Here is my chat packet code:



And here is the Net class code for sending it:



Also, sending string data is tricky since it is variable length.

I don't use Client index 0 because I use that index to determine if the data gets sent out or not. Like any NPC would have cIndex = 0, meaning they are local on the machine, so don't send whatever packet to them. Like if a player did a global chat to all players, the system uses that to determine who gets the chat.

BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 8th Jan 2015 17:43
Thanks, I'll dissect this code and get to grips with it. I hadn't included header data, I'd made a huge assumption that it was taken care of.

Good advice regarding the 0-indexed user. In my immediate case it wouldn't matter, but I'm trying to make a generic solution for any application.

I'm glad you've shared your code and experience, this is days (if not weeks) worth of investigation saved

Quidquid latine dictum sit, altum sonatur
BatVink
Moderator
21
Years of Service
User Offline
Joined: 4th Apr 2003
Location: Gods own County, UK
Posted: 9th Jan 2015 18:42
Update: Success!
I can send and receive messages. I still have to decode the received message in C#, but it's as good as done.

Many thanks again for your code and help. In due course I will post a project template with both AppGameKit and C# files. I have to tidy up first, it's amazing how messy code gets as you test things. I also need to add some scaffolding to keep it upright when things get disconnected. Your code is there in C# but I need to do something similar on the AppGameKit side.

Quidquid latine dictum sit, altum sonatur

Login to post a reply

Server time is: 2024-05-05 21:36:08
Your offset time is: 2024-05-05 21:36:08