Results 1 to 2 of 2

Thread: Winsock byte arrays?

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Dec 2005
    Posts
    92

    Winsock byte arrays?

    Hello, I have searched for awhile, and perhaps I might not know what to search for, but I cannot learn more about using byte arrays to send strings AND/OR UDTs using the same winsock control. Basically, I am making an online client/server game. I have gotten the chat to work, but the UDTs not so much. Ive used examples found on http://support.microsoft.com/defaul...b;EN-US;q152058 which works, but when I use my own UDT, it seems to overflow.

    Here is my UDT:

    VB Code:
    1. Public Type location
    2.     X As Integer
    3.     Y As Integer
    4.     z As Integer
    5. End Type
    6.  
    7. Public Type identity
    8.     account As String
    9.     password As String
    10.     name As String
    11.     gender As String
    12.     Class As String
    13.     subclass1 As String
    14.     subclass2 As String
    15.     subclass3 As String
    16.     age As Integer
    17.     race As String
    18.     level As Integer
    19.     exp As Integer
    20.     skillpts As Integer
    21.     statpts As Integer
    22.     talentpts As Integer
    23.     loc As location
    24.    
    25. End Type
    26.  
    27. Public Type wealth
    28.    
    29.     notes As Integer
    30.     credits As Integer '100 notes = 1 credit
    31.     platinum As Integer '100 credits = 1 platinum
    32.     kesh As Integer '100 platinum = 1 kesh
    33.     lumber As Integer
    34.     food As Integer
    35.         ore As Integer
    36.         steel As Integer
    37.         iron As Integer
    38.         tin As Integer
    39.         stone As Integer
    40.         gold As Integer
    41.         bronze As Integer
    42.         copper As Integer
    43.         silver As Integer
    44.        
    45. End Type
    46.  
    47. Public Type stats
    48.    
    49.     str As Integer
    50.     dex As Integer
    51.     int As Integer
    52.     vit As Integer
    53.     spi As Integer
    54.     ner As Integer 'nerve, depending on number, at low life can get intimidated or fight better
    55.     health As Integer
    56.     mana As Integer
    57.     rage As Integer 'when hit for certain amount, when missing, gain one rage; each point of rage increases miss rate by 5%, but increases damage by 3%
    58.     burnout As Integer 'tiredness, battle fatigue
    59.     hunger As Integer 'if 0, cant eat/drink
    60.     healthRegen As Double
    61.     manaRegen As Double
    62.     rageDegen As Double
    63.    
    64. End Type
    65.  
    66. Public Type combat
    67.  
    68.     armor As Integer
    69.     armorReduc As Double
    70.     avgdmg As Double
    71.     dmgmod As Double
    72.     dodge As Double
    73.     crit As Double
    74.     block As Double
    75.     parry As Double
    76.     tohit As Double
    77.     spellhit As Double 'chance to hit on a spell
    78.     spelldmg As Double
    79.  
    80. End Type
    81.  
    82. Public Type resists
    83.    
    84.     fire As Double
    85.     ice As Double
    86.     nature As Double
    87.     poison As Double
    88.     disease As Double
    89.     shadow As Double
    90.     holy As Double
    91.     magic As Double
    92.    
    93. End Type
    94.  
    95.  
    96. 'faction reputation from 0 to 10 (10 = best, 0 = worst)
    97. Public Type rep
    98.     human As Double
    99.     elf As Double
    100.     orc As Double
    101.     ent As Double
    102.     undead As Double
    103.     centaur As Double
    104.     troll As Double
    105.     dwarf As Double
    106.     leithon As Double
    107.     betobian As Double
    108.     dragon As Double
    109.     yeti As Double
    110.     dryad As Double
    111.     goblin As Double
    112.     ogre As Double
    113.     roc As Double
    114.     satyr As Double
    115.     vampire As Double
    116.     titan As Double
    117.     sabre As Double
    118.     uriah As Double
    119.     razril As Double
    120.    
    121.     jehkuk As Double
    122.     verjak As Double
    123.     bloodwind As Double
    124.  
    125. End Type
    126.  
    127. Public Type inventory
    128.    
    129.     helm As item
    130.     shoulders As item
    131.     chest As item
    132.     back As item
    133.     belt As item
    134.     gloves As item
    135.     legs As item
    136.     boots As item
    137.     righthand As item
    138.     lefthand As item
    139.     ring1 As item
    140.     ring2 As item
    141.     neck1 As item
    142.     neck2 As item
    143.     trinket1 As item
    144.     trinket2 As item
    145.     trinket3 As item
    146.     backpack(40) As item
    147.     pocket(12) As item
    148.     pouch20(5) As item 'gained at level 20
    149.     pouch35(7) As item 'gained at level 35
    150.     pouch50(9) As item 'gained at level 50
    151.     pouch65(11) As item 'gained at level 65
    152.     pouch80(13) As item 'gained at level 80
    153.     pouch95(15) As item 'gained at level 95
    154.  
    155. End Type
    156.  
    157.  
    158. 'house/land/village variables for character
    159. Global acres As Integer
    160. Global armypower As Integer
    161. Global taxrate As Double 'per turn, in credits
    162. Global population As Double
    163.  
    164.  
    165. Public Type hero
    166.  
    167.     identity As identity
    168.     spellList As spellList
    169.     stats As stats
    170.     combat As combat
    171.     resists As resists
    172.     wealth As wealth
    173.     rep As rep 'reputation
    174.     inventory As inventory
    175.    
    176. End Type
    177.  
    178. Public myHero As hero

    Quite hefty, I know, and it will get even larger as i add more things to the game. Reguardless, when it is saved directly to a text file, it is 18kb with a name filled out and the basic entries are put in. I'm not quite sure if it is too large, and it is causing it. I tried sending each sub-UDT (identity, spellList, stats, etc) and it still doesnt work. Anyone have any suggestions?

    OK, moving on, assuming we get this to work, How do I do the array of bytes as a buffer? Ive seen examples and I truly dont get it; if you can point me to a tutorial, explain a bit, or give me the name of a good book I can buy, I'd much appreciate it.

    Thanks!

  2. #2
    Frenzied Member
    Join Date
    Aug 2000
    Location
    O!
    Posts
    1,177

    Re: Winsock byte arrays?

    I have done quite a bit of what you are attempting. One difference that I can see is how we each define the strings in our UDTs. Mine are all fixed length. Each string defined in your UDT is actually a long pointer to a string and will only add 4 bytes to the length of the UDT whereas a 30 character string in my UDT will add 60 bytes to the UDT's length.

    When I CopyMemory the UDT to the byte array, I use the UDT's Len (not the LenB) and in the copy process, the strings are compressed from 16 bit to 8 bit.

    I have never used variable length strings in my UDTs so I just don't know what the CopyMemory will do. I would think that it would simply copy the address to the byte array. And who knows what is stored at that address on the receiving end. Without seeing how you have coded the CopMemory, I can only guess what might be happening.

    I have replied to several posts on this subject in the past. Try doing a search using my id and "udt" as search parameters. If that still doesn't help, let me know.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width