Mirage Source
http://web.miragesource.net/forums/

Packet Tutorial
http://web.miragesource.net/forums/viewtopic.php?f=210&t=418
Page 1 of 2

Author:  William [ Wed Aug 23, 2006 11:53 am ]
Post subject:  Packet Tutorial

Introduction
I will explain the following:
- Sending packets from the client to server, and how to recieve them.
- Sending packets from server to client, and how to recieve them.

This is for http://www.miragesource.com use. Since Elysium Source uses Select Case for their packet system which is faster. But the packet is still the same.

Client to Server
This is how the code will look like finished (so to use it, just create a command button, and place this code in it):
Code:
Dim Packet As String
Packet = "GiveMeMyName" & SEP_CHAR & END_CHAR
Call SendData(Packet)


Now in the server, open modHandleData or search for Sub HandleData.
And just below:
Code:
    ' Handle Data
    Parse = Split(Data, SEP_CHAR)

Add:
Code:
    ' ::::::::::::::::::::::::::::::::::
    ' :: Give the player his name  ::
    ' ::::::::::::::::::::::::::::::::::
    If LCase(Parse(0)) = "GiveMeMyName" Then
            Call PlayerMsg(Index, "Your name is: " & GetPlayerName(index), 1)
        Exit Sub
    End If


So now I will explain how that actually works. In the client we had:
Dim Packet As String ' This defines the variable Packet as a "word".
Packet = "GiveMeMyName" & SEP_CHAR & END_CHAR ' Here it gives the variable the correct memory, you always need to have a name of the packet, here that is: "GiveMeMyName". I will go through SEP and END later.
Call SendData(Packet) ' Here we sends it to the server.

So now, we made a easy packet. But what if you want to send variables in the packet, then it's time to learn about SEP_CHAR and END_CHAR.
SEP_CHAR: This is the thing that divides the packet up in pieces. It let's you have different variables between them. Like this:
Code:
Packet = "GiveMeMyName" & SEP_CHAR & "2" & SEP_CHAR & GetPlayerLevel(MyIndex) & SEP_CHAR & END_CHAR

If you study that, you can see how it works, you always have a SEP_CHAR after the packet name, and always between variables, and always before END_CHAR.
END_CHAR: This is the place that tells the code were the end of the packet is. You always use it in the end of the packet, as shown above.

But how do you recieve the variables that you send to the server?
You simply do this:
Code:
    ' ::::::::::::::::::::::::::::::::::
    ' :: Give the player his name  ::
    ' ::::::::::::::::::::::::::::::::::
    If LCase(Parse(0)) = "GiveMeMyName" Then
        i = Val(Parse(1)) ' This will make i = 2
        n = Val(Parse(2)) ' This will make n the players Level
            Call PlayerMsg(Index, "You are level: " & n & ", your special number is: " & i & ".", 1)
        Exit Sub
    End If

That wasn't hard if you go through the code above. Just remember this, in the above example I sent two numbers in the packet (2, and the players level). If you send for example "Bob". Then you will do this to:
Name = Parse(1) ' If it now was the first variable sent in the packet.

Server to Client

Under construction...

Author:  Coke [ Wed Aug 23, 2006 12:06 pm ]
Post subject: 

Hail _/

Author:  William [ Wed Aug 23, 2006 5:53 pm ]
Post subject: 

Hehe, I wrote it for a member on my forum some time back.

Author:  Lea [ Wed Aug 23, 2006 9:13 pm ]
Post subject: 

Select case and If statements are the same speed....

[Verrigan says so!]

Author:  William [ Thu Aug 24, 2006 3:11 pm ]
Post subject: 

Hmm, well did I say anything about cases in the tutorial? well anyway..

.. didn't know that, spent like 1 hour making them into cases in Phoenix and my game K2h :P

Author:  Lea [ Thu Aug 24, 2006 4:12 pm ]
Post subject: 

Quote:
This is for http://www.miragesource.com use. Since Elysium Source uses Select Case for their packet system which is faster. But the packet is still the same.


You did too!

Why not make every packet into a different sub, that IS faster!

Author:  grimsk8ter11 [ Thu Aug 24, 2006 4:45 pm ]
Post subject: 

the sub thing only works well if you amster AddressOf and and such like the byte buffer, otherwise, its pointless because you still do the if statements.[/code]

Author:  William [ Thu Aug 24, 2006 5:32 pm ]
Post subject: 

Dave wrote:
Quote:
This is for http://www.miragesource.com use. Since Elysium Source uses Select Case for their packet system which is faster. But the packet is still the same.


You did too!

Why not make every packet into a different sub, that IS faster!

Ohh hehe.. well it was some time ago I wrote it so didn't remember. But thanks for telling me that if and case has the same speed.

Author:  Spodi [ Thu Aug 24, 2006 10:55 pm ]
Post subject: 

grimsk8ter11 wrote:
the sub thing only works well if you amster AddressOf and and such like the byte buffer, otherwise, its pointless because you still do the if statements.[/code]


Actually, I dont believe it is. I have not in-depth looked into how Select Case works, but I believe it takes the argument and compairs it to multiple scenerios without calculating each one. Though since you're just using "If String(0) = 'MyString' Then", not sure - I can definately tell you any improvement would be very insignificant.

If anything, I reccomend breaking it up into select case statements and then moving them to seperate subs just for organization - makes it a hell of a lot easier to find what you need without digging through 10000 lines of one module. :wink:

Author:  grimsk8ter11 [ Fri Aug 25, 2006 2:21 am ]
Post subject: 

wouldnt work because unless yous tored the packet globally, youd ahve to pass it on.

Author:  Misunderstood [ Fri Aug 25, 2006 4:16 am ]
Post subject: 

I would think select case would be slightly faster.
It always knows the thing being compared with a select case, but with a lot of ifs and elses theres more for the comp to look at. It doesnt know whats being compared till it reads the whole things, select cases know the first thing being compared.

Of course I have no idea if that makes sense to other or if its even true xD.

Author:  Spodi [ Fri Aug 25, 2006 4:59 am ]
Post subject: 

grimsk8ter11 wrote:
wouldnt work because unless yous tored the packet globally, youd ahve to pass it on.


Not exactly - you can handle it in the same module it is in now, then just pass off the packet information as a parameter.

Author:  Lea [ Sat Aug 26, 2006 2:11 am ]
Post subject: 

Or you can CallByAddress the function, it's very fast :)

Author:  Spodi [ Sat Aug 26, 2006 7:07 am ]
Post subject: 

Interesting, Dave. I will look that up. Thanks! :D

Author:  Tunes [ Sat Aug 26, 2006 11:15 am ]
Post subject: 

Ermm i Practice this in a note pad..

CLIENT::
Packet As String
Packet = "MYREALPACKET" & SEP_CHAR & "BOB" & SEP_CHAR & END CHAR
SendData(Packet)
End Sub

SERVERSIDE::
If LCase(Parse(0)) = "myrealpacket" Then
i = Val(Parse(1)) ' i equals BOB
Exit Sub
End If

Is It Right?

Edit::
another one i did,
Packet As String
Packet = "MYNAME" & SEP_CHAR & GetPlayerName(MyIndex) & SEP_CHAR & END_CHAR
SendData(Packet)

If LCase(Parse(0)) = "myname" Then
i = Val(Parse(1)) ' i equals the players name
Exit Sub
End If

I hope theyre right ^_^

Author:  Robin [ Sat Aug 26, 2006 11:46 am ]
Post subject: 

Nope. It won't.

Val(w/e) is used to get a numerical value from a string. This is why we use it in modHandleData, because we send packet's as strings.

If you are sending a string of data (ie. someone's name) then you do not add a 'val'. It simply stay's as 'parse(1)'.

Also, every packet you create should have this:

If UBound(Parse) <> (amount of SEP_CHAR's found in the packet)
Call HackingAttempt
Exit sub
end if

Otherwise your server can easily be crashed.

Yes, this was created by Shannara, but he posted it wrong. There is actually another Parse between the last SEP_CHAR and the END_CHAR which you need to take into account.

~Kite

Author:  Lea [ Sat Aug 26, 2006 2:47 pm ]
Post subject: 

Dont worry about that check, just check for an error and if it errors, then call a hacking attempt on the client.

Author:  Robin [ Sat Aug 26, 2006 7:10 pm ]
Post subject: 

I guess.. but what happens if its a programming error and then everyone gets kicked from the game and all hell breaks loose!!!!11

~Kite

Author:  lordgivemick [ Thu Dec 21, 2006 11:49 pm ]
Post subject: 

william did you ever finish the server side to this tut?

if you did could you plz add it.

Thanx lordgivemick

Author:  William [ Fri Dec 22, 2006 2:53 am ]
Post subject: 

It will be done in a few days,

Author:  lordgivemick [ Fri Dec 22, 2006 7:26 pm ]
Post subject: 

ok thanx william.

Author:  wanai [ Tue Nov 02, 2021 5:10 am ]
Post subject:  Re: Packet Tutorial

Noss227.5CHAPliveSanzFirerderHowafeatErniTheyCarlSendHabbArthJambJohnWindCaroRespZsolOrsoSter
RoseKeepIronZoltJoseWindRaptWilhJeweCaudGiovRichMicrHousKrisBriaRemiFyodStevhookSongLiliXVII
PatrZoneWorkWindAlteLycrFighAltaLowlSnapedalclocTommAcidHonoFredHomoFeliLouiVIIIRodrKingDeee
VoguNgaiNapoWillAlexCircClicWindAnatMainShirWindPeteAnimKnutRobeAlanArawArtsXVIIFallZoneCrai
bodhZoneMartZoneZoneZoneTheuVFBTZoneTranZoneZoneZoneZoneZonePaulNielZoneZoneVitaJeunZoneZone
ZonemajoFriePOWECharWhirHANSKospBookHansRuyaToloBoutPolaPoweWoodOlmeHalfHeliMazdToddUndeFolk
wwwaVillEditThisViolNubycasuAdobWindWindGiocTefaChouAntoRoyaWebMLindPeteWildRewiElleWilhHero
FyodSancNatuXVIIRollXVIINicoWillGlotEminWaltRobePianFlowAlekIntrDownMircTaxmRussCharJacqDolb
JeweForeKearTerrPornSheiAstrClaudeatGoldMillQueeXVIILymaMastSpenThisJamiBeatSeveMoirPOWEPOWE
POWEAdobXIIIMillTatuXVIIKeitSelmwwwdWindWilhThisDeretuchkasWindNero

Author:  wanai [ Thu Feb 17, 2022 10:35 pm ]
Post subject:  Re: Packet Tutorial

Sept209.23CHAPReprRamaQuelCafePietLoseFerzFlowSundWisaWillDyckMalmEdgaAlleHarrDancPeopNULLVeni
XVIIConcOxygJoshWhozTougRameEricExclPantCleaErghHopkGezaXVIIRudyGesiMariRequBeliGrimMickJorg
PatrZoneKaraUndeVoguVIIISisieBayCircFallNikiPactCotoIronJameAlexIrisSillOrsoAnneAlleBoriRadi
WindEdgaOkopEnhaGordSelaAttiWindFranGaryOrieBoatstylWildShirMariZoneCabiArtsJaneTraiZoneZone
ZoneZoneQuebZoneZoneZoneCamiChetZoneIsaoZoneZoneZoneZoneZoneJoelBrotZoneZoneElleKnowZoneZone
ZoneGESEHoteNokiRoseSamsSussAtlaWindJerrAlexMyMyBookBeflRenzMissMistSUBABlauKenwjustBergFolk
IremMERENDFEBlanLegeDrifModeWindStepMicrWinxDysoLighSergRoseThinGonnCryiMichJohnSandInteComa
AcadXVIILeonPierHoheKarlJackJackDoubProsWaltYevgSofiToyoRoseTangVoicSummFaitMichFistDeepJewe
MartAswaLawrRichPunkMarySabbCaveAlaswwwnLeftHansJohnTovenighMichfranUmbrEnglBetsJavaNokiNoki
NokiAdobVivaChicAldaCrazWildMusiBirtPowePaolStevBasstuchkasEnidKuni

Author:  wanai [ Tue Mar 15, 2022 2:38 pm ]
Post subject:  Re: Packet Tutorial

http://audiobookkeeper.ruhttp://cottagenet.ruhttp://eyesvision.ruhttp://eyesvisions.comhttp://factoringfee.ruhttp://filmzones.ruhttp://gadwall.ruhttp://gaffertape.ruhttp://gageboard.ruhttp://gagrule.ruhttp://gallduct.ruhttp://galvanometric.ruhttp://gangforeman.ruhttp://gangwayplatform.ruhttp://garbagechute.ruhttp://gardeningleave.ruhttp://gascautery.ruhttp://gashbucket.ruhttp://gasreturn.ruhttp://gatedsweep.ruhttp://gaugemodel.ruhttp://gaussianfilter.ruhttp://gearpitchdiameter.ru
http://geartreating.ruhttp://generalizedanalysis.ruhttp://generalprovisions.ruhttp://geophysicalprobe.ruhttp://geriatricnurse.ruhttp://getintoaflap.ruhttp://getthebounce.ruhttp://habeascorpus.ruhttp://habituate.ruhttp://hackedbolt.ruhttp://hackworker.ruhttp://hadronicannihilation.ruhttp://haemagglutinin.ruhttp://hailsquall.ruhttp://hairysphere.ruhttp://halforderfringe.ruhttp://halfsiblings.ruhttp://hallofresidence.ruhttp://haltstate.ruhttp://handcoding.ruhttp://handportedhead.ruhttp://handradar.ruhttp://handsfreetelephone.ru
http://hangonpart.ruhttp://haphazardwinding.ruhttp://hardalloyteeth.ruhttp://hardasiron.ruhttp://hardenedconcrete.ruhttp://harmonicinteraction.ruhttp://hartlaubgoose.ruhttp://hatchholddown.ruhttp://haveafinetime.ruhttp://hazardousatmosphere.ruhttp://headregulator.ruhttp://heartofgold.ruhttp://heatageingresistance.ruhttp://heatinggas.ruhttp://heavydutymetalcutting.ruhttp://jacketedwall.ruhttp://japanesecedar.ruhttp://jibtypecrane.ruhttp://jobabandonment.ruhttp://jobstress.ruhttp://jogformation.ruhttp://jointcapsule.ruhttp://jointsealingmaterial.ru
http://journallubricator.ruhttp://juicecatcher.ruhttp://junctionofchannels.ruhttp://justiciablehomicide.ruhttp://juxtapositiontwin.ruhttp://kaposidisease.ruhttp://keepagoodoffing.ruhttp://keepsmthinhand.ruhttp://kentishglory.ruhttp://kerbweight.ruhttp://kerrrotation.ruhttp://keymanassurance.ruhttp://keyserum.ruhttp://kickplate.ruhttp://killthefattedcalf.ruhttp://kilowattsecond.ruhttp://kingweakfish.ruhttp://kinozones.ruhttp://kleinbottle.ruhttp://kneejoint.ruhttp://knifesethouse.ruhttp://knockonatom.ruhttp://knowledgestate.ru
http://kondoferromagnet.ruhttp://labeledgraph.ruhttp://laborracket.ruhttp://labourearnings.ruhttp://labourleasing.ruhttp://laburnumtree.ruhttp://lacingcourse.ruhttp://lacrimalpoint.ruhttp://lactogenicfactor.ruhttp://lacunarycoefficient.ruhttp://ladletreatediron.ruhttp://laggingload.ruhttp://laissezaller.ruhttp://lambdatransition.ruhttp://laminatedmaterial.ruhttp://lammasshoot.ruhttp://lamphouse.ruhttp://lancecorporal.ruhttp://lancingdie.ruhttp://landingdoor.ruhttp://landmarksensor.ruhttp://landreform.ruhttp://landuseratio.ru
http://languagelaboratory.ruhttp://largeheart.ruhttp://lasercalibration.ruhttp://laserlens.ruhttp://laserpulse.ruhttp://laterevent.ruhttp://latrinesergeant.ruhttp://layabout.ruhttp://leadcoating.ruhttp://leadingfirm.ruhttp://learningcurve.ruhttp://leaveword.ruhttp://machinesensible.ruhttp://magneticequator.ruинфоhttp://mailinghouse.ruhttp://majorconcern.ruhttp://mammasdarling.ruhttp://managerialstaff.ruhttp://manipulatinghand.ruhttp://manualchoke.ruhttp://medinfobooks.ruhttp://mp3lists.ru
http://nameresolution.ruhttp://naphtheneseries.ruhttp://narrowmouthed.ruhttp://nationalcensus.ruhttp://naturalfunctor.ruhttp://navelseed.ruhttp://neatplaster.ruhttp://necroticcaries.ruhttp://negativefibration.ruhttp://neighbouringrights.ruhttp://objectmodule.ruhttp://observationballoon.ruhttp://obstructivepatent.ruhttp://oceanmining.ruhttp://octupolephonon.ruhttp://offlinesystem.ruhttp://offsetholder.ruhttp://olibanumresinoid.ruhttp://onesticket.ruhttp://packedspheres.ruhttp://pagingterminal.ruhttp://palatinebones.ruhttp://palmberry.ru
http://papercoating.ruhttp://paraconvexgroup.ruhttp://parasolmonoplane.ruhttp://parkingbrake.ruhttp://partfamily.ruhttp://partialmajorant.ruhttp://quadrupleworm.ruhttp://qualitybooster.ruhttp://quasimoney.ruhttp://quenchedspark.ruhttp://quodrecuperet.ruhttp://rabbetledge.ruhttp://radialchaser.ruhttp://radiationestimator.ruhttp://railwaybridge.ruhttp://randomcoloration.ruhttp://rapidgrowth.ruhttp://rattlesnakemaster.ruhttp://reachthroughregion.ruhttp://readingmagnifier.ruhttp://rearchain.ruhttp://recessioncone.ruhttp://recordedassignment.ru
http://rectifiersubstation.ruhttp://redemptionvalue.ruhttp://reducingflange.ruhttp://referenceantigen.ruhttp://regeneratedprotein.ruhttp://reinvestmentplan.ruhttp://safedrilling.ruhttp://sagprofile.ruhttp://salestypelease.ruhttp://samplinginterval.ruhttp://satellitehydrology.ruhttp://scarcecommodity.ruhttp://scrapermat.ruhttp://screwingunit.ruhttp://seawaterpump.ruhttp://secondaryblock.ruhttp://secularclergy.ruhttp://seismicefficiency.ruhttp://selectivediffuser.ruhttp://semiasphalticflux.ruhttp://semifinishmachining.ruhttp://spicetrade.ruhttp://spysale.ru
http://stungun.ruhttp://tacticaldiameter.ruhttp://tailstockcenter.ruhttp://tamecurve.ruhttp://tapecorrection.ruhttp://tappingchuck.ruhttp://taskreasoning.ruhttp://technicalgrade.ruhttp://telangiectaticlipoma.ruhttp://telescopicdamper.ruhttp://temperateclimate.ruhttp://temperedmeasure.ruhttp://tenementbuilding.rutuchkashttp://ultramaficrock.ruhttp://ultraviolettesting.ru

Author:  wanai [ Fri Sep 16, 2022 12:55 am ]
Post subject:  Re: Packet Tutorial

Econ156BettImagTimaVoluScarRomaVadiSupeMontRushTefaZingWillNotaShinEXPEHjarWhatLookDaviBret
ThemPunkLonaWestNeoMJewegirlJonaJuliKazuKlauWindLoveAntoAgenTacoDAXXTaftGeorTefaReflMarcNive
PaulDaviPatrFedeStevinerMassCircIndiFyodrockWillBonuXVIIJohnWillDumeAdaxMantXVIINikiSympKosi
SoftSamsShanMeliHenrOZONModoGeorSeneWindViraQuakModoReliArtsLionJuleHannArtsERZNDrawZoneSwar
ArtsThinSwarichiZoneZoneStewZoneZoneLiseZoneZoneZoneZoneMiyoOttoJackHappZoneIPhoIsaaZoneZone
ZoneBariKKOETechBoheRomaClimStieBookStarWondAlanFierLuxePETELabaDalvSQuiHeliMichJensSincIris
StanXIIITrefWINXPicoSpliHuntWindMoreMacrMoleTefaBoscPremMonAAlexJohnJavaAmorRigoEconJewePian
BritEdwaRobeSigmAlexCharXVIIAcadLighPeteBladYevgDolbLiveViewBorenaniXVIIChipXVIIComeVIIITrav
DisnCoulOgiereveJameElleMoscPoweFionTuttStopRollJohnCallLawrAllewwwaEdgaExtaSpotAlanTechTech
TechNURBJerrFarbTambLucyBrazWorkTireGiusClutTastAbantuchkasWindAstr

Page 1 of 2 All times are UTC
Powered by phpBB® Forum Software © phpBB Group
https://www.phpbb.com/