docs: Added docs for Packet class and onPacket event

fix: Added missing sendToAll method
This commit is contained in:
AURUMVORXX
2024-11-05 03:33:46 +03:00
parent 2657b2c613
commit 5389f6dcb4
4 changed files with 153 additions and 0 deletions

View File

@@ -0,0 +1,3 @@
# `class` Packet
---
::: g2o.packets.Packet

View File

@@ -0,0 +1,22 @@
# `event` onPacket
This event is triggered when new packet arrives from the client.
Original: [onPacket](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/server-events/network/onPacket/)
## Parameters
* `dict` **kwargs**:
* `int` **playerid**: the id of the player who sent the packet.
* `Packet` **packet**: data sended over network from client side.
## Usage
```python
import g2o
@g2o.event('onPacket')
def onPacketEvt(**kwargs):
data = kwargs['data']
message = data.readString()
print(f'Got packet from {kwargs['playerid']} (bytes used {data.bytesUsed})')
print(f'Packet says: {message}')
```

View File

@@ -1,67 +1,190 @@
import sqg2o
class Packet(sqg2o.Packet):
"""
This class represents data packet that gets send over the network.
Original: [Packet](https://gothicmultiplayerteam.gitlab.io/docs/0.3.0/script-reference/server-classes/network/Packet/)
## `int` bitsUsed
Represents the total number of bits used by the script packet data.
## `int` bytesUsed
Represents the total number of bytes used by the script packet data.
"""
def __init__(self):
return super().__init__()
def reset(self):
"""
This method will clear the packet data, making it empty.
"""
return super().reset()
def send(self, playerid : int, reliability : int):
"""
This method will send the packet data to the specified player.
**Parameters:**
* `int` **playerid**: the id of the player to whom you want to send the packet.
* `int` **reliability**: the reliability type, for more information see **TBD**.
"""
return super().send(playerid, reliability)
def sendToAll(self, reliability : int):
"""
This method will send the packet data to the specified player.
**Parameters:**
* `int` **reliability**: the reliability type, for more information see **TBD**.
"""
return super().send(playerid, reliability)
def writeInt8(self, value : int):
"""
This method will append signed int8 value to the packet. (1 byte)
**Parameters:**
* `int` **value**: the number value in range -128 to 127.
"""
return super().writeInt8(value)
def writeUInt8(self, value : int):
"""
This method will append unsigned int8 value to the packet. (1 byte)
**Parameters:**
* `int` **value**: the number value in range 0 to 255.
"""
return super().writeInt8(value)
def writeInt16(self, value : int):
"""
This method will append signed int16 value to the packet. (2 bytes)
**Parameters:**
* `int` **value**: the number value in range -32768 to 32767.
"""
return super().writeInt16(value)
def writeUInt16(self, value : int):
"""
This method will append unsigned int16 value to the packet. (2 bytes)
**Parameters:**
* `int` **value**: the number value in range 0 to 65535.
"""
return super().writeInt16(value)
def writeInt32(self, value : int):
"""
This method will append signed int32 value to the packet. (4 bytes)
**Parameters:**
* `int` **value**: the number value in range -2147483648 to 2147483647.
"""
return super().writeInt32(value)
def writeUInt32(self, value : int):
"""
!!! note
By default squirrel uses int32 values, which means that this method behaves exactly the same as [writeInt32](Packet.md#g2o.packets.Packet.writeInt32) in scripts.
This method will append unsigned int32 value to the packet. (4 bytes)
**Parameters:**
* `int` **value**: the number value in range 0 to 4294967295.
"""
return super().writeInt32(value)
def writeBool(self, value : bool):
"""
This method will append boolean value to the packet. (1 bit)
**Parameters:**
* `bool` **value**: the boolean value.
"""
return super().writeBool(value)
def writeFloat(self, value : float):
"""
This method will append float value to the packet. (4 bytes)
**Parameters:**
* `float` **value**: the number value.
"""
return super().writeFloat(value)
def writeString(self, value : str):
"""
!!! note
The amount of bytes appended to the packet depends on the length of string, 1 byte = 1 char.
This method will append string value to the packet.
**Parameters:**
* `str` **value**: the text value.
"""
return super().writeString(value)
def readInt8(self,) -> int:
"""
This method will get signed int8 value from the packet. (1 byte)
**Returns `int`:**
the number value in range -128 to 127.
"""
return super().readInt8()
def readUInt8(self,) -> int:
"""
This method will get unsigned int8 value from the packet. (1 byte)
**Returns `int`:**
the number value in range 0 to 255.
"""
return super().readInt8()
def readInt16(self) -> int:
"""
This method will get signed int16 value from the packet. (2 bytes)
**Returns `int`:**
the number value in range -32768 to 32767.
"""
return super().readInt16()
def readUInt16(self) -> int:
"""
This method will get unsigned int16 value from the packet. (2 bytes)
**Returns `int`:**
the number value in range 0 to 65535.
"""
return super().readInt16()
def readInt32(self) -> int:
"""
This method will get signed int32 value from the packet. (4 bytes)
**Returns `int`:**
the number value in range -2147483648 to 2147483647.
"""
return super().readInt32()
def readUInt32(self) -> int:
"""
This method will get unsigned int32 value from the packet. (4 bytes)
**Returns `int`:**
the number value in range 0 to 4294967295.
"""
return super().readInt32()
def readBool(self) -> bool:
"""
This method will get signed int8 value from the packet. (1 byte)
**Returns `bool`:**
the boolean value.
"""
return super().readBool()
def readFloat(self) -> float:
"""
This method will get float value from the packet. (4 bytes)
**Returns `float`:**
the number value.
"""
return super().readFloat()
def readString(self) -> str:
"""
!!! note
The amount of bytes appended to the packet depends on the length of string, 1 byte = 1 char.
This method will get string value from the packet.
**Returns `str`:**
the text value.
"""
return super().readString()
@property

View File

@@ -25,6 +25,8 @@ nav:
- onTime: defaultEvents/general/onTime.md
- onBan: defaultEvents/general/onBan.md
- onUnban: defaultEvents/general/onUnban.md
- Network:
- onPacket: defaultEvents/network/onPacket.md
- Player:
- onPlayerChangeColor: defaultEvents/player/onPlayerChangeColor.md
- onPlayerChangeFocus: defaultEvents/player/onPlayerChangeFocus.md
@@ -57,6 +59,9 @@ nav:
- onPlayerSpellSetup: defaultEvents/player/onPlayerSpellSetup.md
- onPlayerTeleport: defaultEvents/player/onPlayerTeleport.md
- onPlayerToggleFaceAni: defaultEvents/player/onPlayerToggleFaceAni.md
- Classes:
- Network:
- Packet: classes/network/Packet.md
- Functions:
- Events:
- event: events/event.md