![]() |
IOCP (Not for Win 9x/ME) (Bugs Fixed) - Printable Version +- Mirage Engine (https://mirage-engine.uk/forums) +-- Forum: Mirage Source (Nostalgia) (https://mirage-engine.uk/forums/forumdisplay.php?fid=61) +--- Forum: Archive (2006-2011) (https://mirage-engine.uk/forums/forumdisplay.php?fid=18) +---- Forum: Resources (https://mirage-engine.uk/forums/forumdisplay.php?fid=49) +---- Thread: IOCP (Not for Win 9x/ME) (Bugs Fixed) (/showthread.php?tid=507) |
IOCP (Not for Win 9x/ME) (Bugs Fixed) - William - 20-12-2006 Originally posted by Verrigan Difficulty (Copy & Paste): Medium 3/5 Difficulty (Understanding): Hard 5/5 As always, even though most don't pay attention to my warnings, you should read this tutorial in its entirety before adding it to your game. There's your warning.. I'm sure some of you will just start copying & pasting.. Don't expect to learn much from it if you do. ![]() ![]() First, let me just say that (as the Subject says) this modification will make it so you can not run your server on Windows 9x or Windows ME. IOCP (Input/Output Completion Ports) only works on NT-Based operating systems. (NT/2K/XP/2003+) That said, I have a question for you. Win 9x/ME are not built to handle a lot of connections anyways, so why would you want to run an online game server on a Win 9x-Based machine to begin with? If you are programming on a Win 9x-Based machine, you will not be able to test the server on this machine after these modifications. These changes are only on the server side, so will not affect the client in any way. You do not have to make ANY changes to the client to put IOCP in the server. ![]() Let's get down to business. This tutorial has been developed for Mirage Source Engine - Build 1. I will not support adding these changes to any other version of Mirage Source, including your own modified versions of Mirage Source Engine - Build 1. In reality, the copy/pasting difficulty of this tutorial is more like 1.5/5, but I set it to 3/5 because I am familiar with these forums and its usual users, and I know you will want to put this in your modified MSE, or older versions of Mirage Source. Again, I am telling you, I will NOT support putting this in your code. However, if you are adding this to MSE - Build 1, and are having difficulty, or find any bugs, feel free to post here. ![]() Now, as always, you should [shadow=red,left][size=14pt]ALWAYS BACKUP YOUR SOURCE[/shadow] before adding any tutorial to your game. You are going to be making a lot of modifications, and you might get lost and/or forget something.. So, make sure you backup first! I have made this tutorial in such a way that you will not have to make many modifications to the way the data is handled on the server. You will only have to make modifications to how sockets are handled, and the data received/sent through them. This method of using IOCP requires a separate .DLL file. It is a COM object, written in C++ by Jetbyte. You can find the original .DLL file, its source, and documentation for it at http://www.jetbyte.com/portfolio-showar ... rticleId=4 1&catId=1&subcatId=3. Unfortunately, the .DLL/source available on Jetbyte's website will only allow you to write 1024 bytes to a socket, (Thanks, Misunderstood, for helping me figure this out on my test chat-server ![]() ![]() Warning: With Jetbyte's original .DLL, you will not be able to set the local IP address to your network card's IP address. It will cause a fatal error, and the server will not work. (In it's original form, your local IP address for the server can only be "0.0.0.0") So, I suggest you use my .DLL which also allows for the sending of the larger packets. ![]() Whichever one you use, you will need to register the .DLL. There are a couple of ways you can do this. From the command prompt, you can type: regsvr32 . (i.e. If you put the .DLL in C:\MyGame, you would do: regsvr32 C:\MyGame\COMSocketServer.dll) Another way to do this is to go to your server's references, and browse to the .DLL file. When you add the file to your server's references, which you need to do anyway, it will automatically register the .DLL for you. The reason I told you both ways is because if you run the server on a different computer, you will need to register the .DLL on that other computer. ![]() Now let's get on with the tutorial! (Yay) Needed Files: COMSocketServer.dll (See paragraphs above for downloads) Files You Will Add clsServer.cls clsSocket.cls colSockets.cls Files to Modify frmServer.frm modConstants.bas modGameLogic.bas modGeneral.bas modServerTCP First let's start with the files you will need to add. They are all class modules, so just add 3 blank class modules to your server project, and give them the names you see above. (without the ".cls" - i.e. For the clsServer.cls class module, the name would be: clsServer) These files will be fairly easy, as they are all Copy & Paste. Please forgive me for the poor commenting. ![]() [size=14pt]clsServer.cls - This will be the server object. The actual socket server will be initialized and stored in this object. So will our sockets collection. ![]() Code: Option Explicit [size=14pt]clsSocket.cls - Our custom Socket object to store connection information. Code: Option Explicit [size=14pt]colSockets.cls - Our custom collection of our clsSocket objects. You will need to load the Class Builder Utility for this, so you can change this class module into a collection. You will also have to set the "Item" property as default. (Look at the class builder utility. You will see it.) (See Add-Ins/Add-In Manager to load the utility) Code: Option Explicit Easy Peasy, One Two Threesy.. Now we get to the "difficult" part. ![]() The first thing you need to do is delete the Winsock control from frmServer. Then remove Microsoft Winsock Control from your components list. Then make the following modifications. ![]() [size=14pt]frmServer.frm - Used to contain the winsock control, and handle all winsock requests. (amongst other things..) Delete or comment the following code: Code: Private Sub Socket_ConnectionRequest(Index As Integer, ByVal requestID As Long) [size=14pt]modConstants.bas - Stores all the global constant variables for the server. After the following: Code: ' Winsock globals Code: Public Const GAME_IP = "0.0.0.0" 'You can leave this, or use your IP. Change: Code: Public Const MAX_PLAYERS = 70 Code: Public Const MAX_PLAYERS = 500 'For starters... More optimization needed for a lot more. [size=14pt]modGameLogic.bas - Handles all the logical stuff for the server. In Function GetPlayerIP(), change: Code: GetPlayerIP = frmServer.Socket(Index).RemoteHostIP Code: GetPlayerIP = GameServer.Sockets(Index).RemoteAddress [size=14pt]modGeneral.bas - Handles general stuff, like server initialization, and termination. ![]() In Sub InitServer(): Change: Code: frmServer.Socket(0).RemoteHost = frmServer.Socket(0).LocalIP Code: Set GameServer = New clsServer Change: Code: Load frmServer.Socket(i) Code: Call GameServer.Sockets.Add(CStr(i)) Change: Code: frmServer.Socket(0).Listen Code: GameServer.StartListening Change: Code: For i = 1 To MAX_PLAYERS Code: For i = 1 To MAX_PLAYERS In Sub ServerLogic(), delete the following: Code: Dim i As Long [size=14pt]modServerTCP.bas - Handles the TCP/IP stuff for the server. At the top of the module, under any Option statements, add the following: Code: Public GameServer As clsServer In Sub UpdateCaption(), change: Code: frmServer.Caption = "Mirage Source Server (" & TotalOnlinePlayers & ")" Code: frmServer.Caption = "Mirage Source Server (" & TotalOnlinePlayers & ")" In Function IsConnected(), change: Code: Function IsConnected(ByVal Index As Long) As Boolean Code: Function IsConnected(ByVal Index As Long) As Boolean In Function IsMultiIPOnline(), change: Code: If IsConnected(i) And Trim(GetPlayerIP(i)) = Trim(IP) Then Code: If IsConnected(i) Then Change Sub SendDataTo() to: Code: Sub SendDataTo(ByVal Index As Long, ByVal Data As String) Change Sub AcceptConnection() to: Code: Sub AcceptConnection(Socket As JBSOCKETSERVERLib.ISocket) Change Sub IncomingData() to:[code]Sub IncomingData(Socket As JBSOCKETSERVERLib.ISocket, Data As JBSOCKETSERVERLib.IData) On Error Resume Next Dim Buffer As String Dim dbytes() As Byte Dim Packet As String Dim top As String * 3 Dim Start As Integer Dim Index As Long Dim DataLength As Long dbytes = Data.Read Socket.RequestRead Buffer = StrConv(dbytes(), vbUnicode) DataLength = Len(Buffer) Index = CLng(Socket.UserData) If Buffer = "top" Then top = STR(TotalOnlinePlayers) Call SendDataTo(Index, top) Call CloseSocket(Index) End If Player(Index).Buffer = Player(Index).Buffer & Buffer Start = InStr(Player(Index).Buffer, END_CHAR) Do While Start > 0 Packet = Mid(Player(Index).Buffer, 1, Start - 1) Player(Index).Buffer = Mid(Player(Index).Buffer, Start + 1, Len(Player(Index).Buffer)) Player(Index).DataPackets = Player(Index).DataPackets + 1 Start = InStr(Player(Index).Buffer, END_CHAR) If Len(Packet) > 0 Then Call HandleData(Index, Packet) End If Loop ' Check if elapsed time has passed Player(Index).DataBytes = Player(Index).DataBytes + DataLength If GetTickCount >= Player(Index).DataTimer + 1000 Then Player(Index).DataTimer = GetTickCount Player(Index).DataBytes = 0 Player(Index).DataPackets = 0 Exit Sub End If ' Check for data flooding If Player(Index).DataBytes > 1000 And GetPlayerAccess(Index) - Aaron - 21-12-2006 tried it and its coming up with an error in an area when... Quote:In Function IsConnected(), change:Code:Did everything as said and checked it over 3 times to make sure i made no mistakes in it and i entered it into a fresh MSE so im not sure... - Tony - 22-12-2006 Download the COMSocketServer.dll . Put it into your server folder and go to references and browse into your server folder for it. Do this twice as it won't work the first time. If you did this then just tell me. If you did this step then did you add in class builder and make the class module into a col.? :: Pando - TheRealDamien - 14-01-2007 you installed the support files on your server computer? - Xlithan - 18-01-2007 Deleted post This tutorial is bugged. I read and did everything it said. Some parts are written incorrectly but it's just 1 bug after another. - Tony - 18-01-2007 lol, Your totally wrong. This is easy as 123 abc. Its not bugged at all. - Robin - 18-01-2007 GameBoy, go try on a Vanilla copy. - Matt - 19-01-2007 Zel isn't a noob programmer, just so you guys know. So talking to him in that way, doesn't really help. Not directed at you Kite. Since what you said was actually constructive. - Rian - 19-01-2007 My Classes Try using my classes. Not sure if that's your problem or not, but it's worth a shot. If it still doesn't work, at least you'll know that the classes aren't the problem ![]() - Xlithan - 19-01-2007 Thank you Advocate. I made 1 or 2 corrections first, but I still kept getting errors. I've added this before, but with Elysium Diamond. My copy of Mirage Source is pretty much clean, I've only updated parts of the code which have nothing to do with the connections bits. I'll try again though later and see if it was just something I'd missed. I know there was a lot of changes I had to make to the tutorial. I found that this version seems to work better though: http://www.splamm.com/elysium/forums/vi ... php?t=1658 - Tony - 19-01-2007 Advocate Wrote:Zel isn't a noob programmer, just so you guys know. So talking to him in that way, doesn't really help. I never said that he was a noob prorammer, just correcting him that this tutorial is NOT bugged. kthxbye. - Matt - 19-01-2007 I understand that, but the method you went about, made him sound like a noob. That's all. Try to speak more mature next time. ^_^ - Xlithan - 23-01-2007 Has anybody added this to a fresh copy of MSE 1 without any modifications to the source or the tutorial, and had it working correctly? - Joost - 24-01-2007 I had some errors with it too, but my MS is quite modified. - Tony - 24-01-2007 Depends, are you using my poke source? It already has IOCP within it. IOCP Problem - Godlord - 08-03-2007 Hey, I installed this and I get RTE438, something doesn't exist and I replaced (index) to .item(index) in the yellow marked text and it worked the only problem is that I can't login on the client and that I stay on the text Connected. Does somebody know how to fix this? - Xlithan - 08-03-2007 for 1, use Sonire's classes, that'll fix most of the problems. Secondly, I used the tutorial on Elysium Diamond, and it works in Mirage Source too. - Godlord - 08-03-2007 It fixed the problem ![]() - Matt2 - 03-05-2007 Well, anyone want to post a dl for the .dll? It's not hosted by Verrigan anymore, it seems. - Rian - 04-05-2007 Try Verrigans again, I'm under the impression that there was a period or something in the url that made it bad. If not, I'll upload it when I get off work. - Matt2 - 07-05-2007 His isn't working, I already tried to remove the period. Anyone wanna spare me this file? - Matt - 07-05-2007 http://www.codeproject.com/internet/com ... ct=1639255 That site has both the dll and the source code for the dll. You have to sign up to download it though. - Matt2 - 07-05-2007 I actually found the DLL on another thread on these forums. The Search Button works wonders. Thank you all for your help, though. Re: IOCP (Not for Win 9x/ME) (Bugs Fixed) - ziom10 - 27-10-2009 can anyone reupload files? |