sg_packets.nim 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109
  1. import genpacket_enet, nativesockets, net, md5, enet
  2. defPacketImports()
  3. type
  4. PacketID* = char
  5. template idpacket(pktName, id, s2c, c2s: untyped) {.dirty.} =
  6. let `H pktName`* {.inject.} = id
  7. defPacket(`Sc pktName`, s2c)
  8. defPacket(`Cs pktName`, c2s)
  9. forwardPacketT(uint8, int8)
  10. forwardPacketT(uint16, int16)
  11. forwardPacketT(Port, int16)
  12. idPacket(Login, 'a',
  13. tuple[id: int32; alias: string; sessionKey: string],
  14. tuple[alias: string, passwd: string])
  15. let HZoneJoinReq* = 'j'
  16. defPacket(CsZoneJoinReq, tuple[session: ScLogin])
  17. defPacket(ScZoneRecord, tuple[
  18. name: string = "", desc: string = "",
  19. ip: string = "", port: Port = 0.Port])
  20. idPacket(ZoneList, 'z',
  21. tuple[network: string = "", zones: seq[ScZoneRecord]],
  22. tuple[time: string])
  23. let HPoing* = 'p'
  24. defPacket(Poing, tuple[id: int32, time: float32])
  25. type ChatType* = enum
  26. CPub = 0'i8, CPriv, CSystem, CError
  27. forwardPacketT(ChatType, int8)
  28. idPacket(Chat, 'C',
  29. tuple[kind: ChatType = CPub; fromPlayer: string = ""; text: string = ""],
  30. tuple[target: string = ""; text: string = ""])
  31. idPacket(Hello, 'h',
  32. tuple[resp: string],
  33. tuple[i: int8 = 14])
  34. let HPlayerList* = 'P'
  35. defPacket(ScPlayerRec, tuple[id: int32; alias: string = ""])
  36. defPacket(ScPlayerList, tuple[players: seq[ScPlayerRec]])
  37. let HTeamList* = 'T'
  38. defPacket(ScTeam, tuple[id: int8; name: string = ""])
  39. defPacket(ScTeamList, tuple[teams: seq[ScTeam]])
  40. let HTeamChange* = 't'
  41. idPacket(ZoneQuery, 'Q',
  42. tuple[playerCount: uint16], ##i should include a time here or something
  43. tuple[pad: char = '\0'])
  44. type SpawnKind = enum
  45. SpawnDummy,
  46. SpawnItem, SpawnVehicle, SpawnObject
  47. forwardPacketT(SpawnKind, int8)
  48. defPacket(ScSpawn, tuple[
  49. kind: SpawnKind; id: uint16; record: uint16; amount: uint16])
  50. type TAssetType* = enum
  51. FDummy,
  52. FZoneCfg, FGraphics, FSound
  53. forwardPacketT(TAssetType, int8)
  54. forwardPacket(MD5Digest, array[0..15, int8])
  55. idPacket(FileChallenge, 'F',
  56. tuple[file: string; assetType: TAssetType; fullLen: int32],
  57. tuple[needFile: bool; checksum: MD5Digest])
  58. let HChallengeResult* = '('
  59. defPacket(ScChallengeResult, tuple[status: bool])
  60. let HFileTransfer* = 'f'
  61. defPacket(ScFileTransfer, tuple[fileSize: int32; pos: int32; data: string])
  62. defPacket(CsFilepartAck, tuple[lastpos: int32])
  63. ##dir server messages
  64. let HZoneLogin* = 'u'
  65. defPacket(SdZoneLogin, tuple[name: string; key: string; record: ScZoneRecord])
  66. defPacket(DsZoneLogin, tuple[status: bool])
  67. let HDsMsg* = 'c'
  68. defPacket(DsMsg, tuple[msg: string])
  69. let HVerifyClient* = 'v'
  70. defPacket(SdVerifyClient, tuple[session: ScLogin])
  71. when true:
  72. var buf = newBuffer(100)
  73. var m = toMd5("hello there")
  74. echo(repr(m))
  75. buf.pack m
  76. echo(repr(buf.data))
  77. echo(len(buf.data))
  78. buf.reset()
  79. var x = buf.readMD5Digest()
  80. echo(repr(x))