sg_packets.nim 2.7 KB

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