UPnP -- no more port forwarding

Posted By: JibbSmart

UPnP -- no more port forwarding - 02/23/11 23:22

DOWNLOAD DLL HERE

Make sure to read the README, as it has some licence requirements. The licence requirements aren't mine, but I have to include them since I'm mostly using someone else's code (the licence permits it).

So what does it do? It lets you use UPnP to have your game automatically set up port-forwarding for you. Most routers support it, but not all, so you should still include documentation in your app to instruct those who want to host and will have to do port-forwarding manually.

Opening and closing ports takes about a second. Since this isn't an engine function, there should be nothing wrong with calling the functions in a separate thread to avoid interrupting game flow.

I'm going to try and do that in the next version of KarBOOM.
EDIT2: Threading with UPnP works like a charm.

Anyway, have fun laugh

Jibb

EDIT: Should this be here or in Lite-C Contributions? This forum seems to apply to non-code assets.

EDIT2: Same link, updated version that should eliminate the need for "msvcr100.dll".

EDIT3: msvcr100.dll is included.
Posted By: Superku

Re: UPnP -- no more port forwarding - 02/23/11 23:29

Thank you very much, Jibb, that's a neat contribution! wink
Posted By: Redeemer

Re: UPnP -- no more port forwarding - 02/24/11 04:55

Good contribution! Although I must honestly say that the firewall my gateway uses does not support UPnP, so this is useless to me. tongue

Originally Posted By: JibbSmart
Should this be here or in Lite-C Contributions? This forum seems to apply to non-code assets.

Lite-C Contributions is for contributions of purely Lite-C code. This is a plugin, so I think it doesn't belong there...

EDIT: Scratch that, I just saw this description of the Lite-C Contributions forum:
Quote:
This forum is for code snippets or external DLL implementations to the lite-C game programming language.

I think it's pretty clear where this belongs, then.
Posted By: alibaba

Re: UPnP -- no more port forwarding - 02/24/11 07:10

Danm my Router is not Upnp enabled >.<" However iŽll definately use this laugh Thank you sooo much laugh !!
Posted By: Dark_samurai

Re: UPnP -- no more port forwarding - 02/24/11 07:36

^^ I also made a small UPnP implementation the last week. Are you using a library or have you implemented the UPnP protocol for yourself?
Posted By: alibaba

Re: UPnP -- no more port forwarding - 02/24/11 08:20

@Dark_Samurai
Great! So we will get intergreated UPnP in ANet? Hopefully ^^
Posted By: Dark_samurai

Re: UPnP -- no more port forwarding - 02/24/11 11:24

Exactly ;-) but i have to finish work on some other features until the next release.
Posted By: JibbSmart

Re: UPnP -- no more port forwarding - 02/24/11 13:56

@Dark Samurai: I'm using MiniUPnP. I'd love to have done it all myself, but I had no idea where to start. Since I'm only using a small part of MiniUPnP I want to poke around and make my own smaller version that doesn't use someone else's library, so I don't have to worry about including other people's licences.

If I do get around to that, I'll put that up here.

And if a moderator could move this to Lite-C Contributions, that'd be much appreciated laugh

Jibb

EDIT: What about you, Dark Samurai? Did you implement it yourself or use a library?
Posted By: Dark_samurai

Re: UPnP -- no more port forwarding - 02/24/11 14:58

No I'm using the same library. Implementing such protocols is a very difficult task. This is only really possible if you have a document that describes the standard of the protocol. Otherwise it won't work properly with all devices.
Posted By: JibbSmart

Re: UPnP -- no more port forwarding - 02/24/11 14:59

Fair enough. I'm content to stick with MiniUPnP and include the licence.

Jibb
Posted By: JibbSmart

Re: UPnP -- no more port forwarding - 02/25/11 01:55

New version. Same link in original post. It should [doesn't] eliminate any need for external DLLs (such as "msvcr100.dll").

Please let me know if there are any other problems!

Jibb

EDIT: Btw, could someone please move this to "Lite-C Contributions"? Thanks laugh

EDIT2: Same link, same DLL. But now the zip contains msvcr100.dll, which should also be included in your project to make sure there are no issues on computers that haven't got the Microsoft Visual C++ 2010 Redistributable installed.
Posted By: William

Re: UPnP -- no more port forwarding - 02/26/11 11:26

How do I enable threading so it doesn't interrupt game flow? laugh
Posted By: JibbSmart

Re: UPnP -- no more port forwarding - 02/26/11 14:57

It's not in the DLL. Check out how to do multi-threading here. Just have a function whose job it is to open the ports by calling the DLL function (let's call it threadOpenFunc). Then I just go:
Code:
CreateThread(NULL, 0, threadPortOpenFunc, 1, 0, NULL);

I put that in its own function, actually, and it checks and sets a couple of global variables to make sure that such a thread isn't already opening on closing ports, because it would get unpredictable if you were trying to close a port in one thread while opening the same port in another thread.

Jibb
Posted By: William

Re: UPnP -- no more port forwarding - 02/28/11 00:48

Thanks! I never seen the dll before, I'll look into it. I've installed your .dll with Silas, and it seems to be working good so far. Thanks again for this, and I put your name in the credits. laugh
Posted By: JibbSmart

Re: UPnP -- no more port forwarding - 02/28/11 00:55

No need for my name in the credits -- there's very little of my own code. I'm looking forward to trying Silas -- I have a really busy week ahead of me and can't download it just yet, but I'm excited to see you've put a beta in the Projects forum!

The CreateThread function doesn't need a DLL -- all you need to do is #include <windows.h> laugh

Jibb
Posted By: William

Re: UPnP -- no more port forwarding - 02/28/11 01:13

Ahhh yes, okay. I hope to use the threading for database maybe too. But then again, I'm sure if the database .dll supports it.. does the .dlls need to have some sort of built in support to use threading?

You solved a big problem for me, so that's why the thanks in the credits. laugh
Posted By: JibbSmart

Re: UPnP -- no more port forwarding - 02/28/11 03:25

Cheers laugh

I don't think the DLL itself needs to directly support it, but I could be wrong. To be safe, I'd avoid letting related DLL functions run in more than one thread at the same time, lest they interfere with each other.

Jibb
© 2024 lite-C Forums