Commit Graph

103 Commits

Author SHA1 Message Date
b07e9ddbcb merged internal/service -> cnet/service 2023-12-01 19:22:49 -06:00
af867ccff2 renamed cnet.CNPeer -> cnet.Peer 2023-12-01 19:15:00 -06:00
c60017f78f rename cnpeer package to cnet 2023-12-01 17:11:41 -06:00
e1804a1042 merged entity/chunk && entity/chunkposition 2023-12-01 17:03:46 -06:00
bcc999db38 moved internal/entity to shard/entity 2023-12-01 16:56:55 -06:00
e355af19ab moved internal/protocol/cnpeer to cnpeer
also started a util package
2023-12-01 15:29:19 -06:00
0ed19ad6c5 tests workflow: add timeout
some of the tests can fail in really bad, slow ways. make sure we don't
spin our wheels waiting for a failed test to never fail.
2023-12-01 14:10:45 -06:00
66fe3c9738 TestService: minor refactor; clearer waitgroup Add 2023-12-01 14:08:17 -06:00
72dbfe2541 TestService: wait for OnConnect && OnDisconnect 2023-12-01 13:58:57 -06:00
8e65a78d07 testing refactor; use github.com/matryer/is
It is syntactically pretty, simple, and also makes failures have
pretty colors. what more could you ask for :)
2023-12-01 13:49:50 -06:00
f4b17906ce more protocol/service refactor
- removed protocol.Event: CNPeers now send protocol.PacketEvents
- peer uData is held in CNPeer, use SetUserData() and UserData() to
set/read it
- Service.PacketHandler calback has changed, removed uData:
switched calls to peer.SetUserData() and peer.UserData() where appropriate
- service.Service lots of tidying up, removed dependence on old
protocol.Event.
- service.Service && protocol.CNPeer now accept a cancelable context.
hooray graceful shutdowns and unit tests!
- general cleanup
2023-12-01 00:56:34 -06:00
c0ba365cf5 CNPeer/Service refactor
- each CNPeer is given a unique chan *protocol.Event to pass events to
the service.handleEvents() loop. this is now passed to CNPeer.Handler()
as opposed to NewCNPeer().
- service has basically been rewritten. handleEvents() main loop uses
reflect.SelectCase() now to handle all of the eRecv channels for each
peer
- new protocol Event type: EVENT_CLIENT_CONNECT
- Added service_test.go; blackbox-styled testing like the others.
TestService() starts a service and spins up  a bunch of dummy peers
and verifies that each packet sent causes the corresponding packet
handler to be called.
2023-11-29 19:57:45 -06:00
d0346b2382 use proper errors for db.Err
- switch to using errors.Is where applicable
2023-11-29 19:52:10 -06:00
18a6c5ab42 oh, this is safe actually
https://stackoverflow.com/a/23230406
2023-11-28 21:21:24 -06:00
3abba0ca3c this should be CompareAndSwap oopsd D: 2023-11-27 21:34:39 -06:00
1f66acfd25 holy refactor
started out as me making a service abstraction..

- db.Player exists again, and entity.Player uses it as an embedded struct
- chunk.ForEachEntity() lets you add/remove entities during iteration now
- removed account related fields from CNPeer
- protocol/pool has been merged with protocol.
use protocol.GetBuffer() and protocol.PutBuffer().
- new protocol/internal/service!
service.Service is an abstraction layer to handle multiple CNPeer*
connections and allows you to associate each with an interface{} uData.
In the future it might also handle a task queue for jobs that
modify/interact with the player's uData, called from service.handleEvents()
- PacketHandler callback type has a new param! uData is passed as well now
- much of loginserver/shardserver is now handled by the shared service
abstraction
- SHARD: NPC_ENTER packets are now sent on player loading complete
rather than on enter.
2023-11-27 21:23:28 -06:00
d8277ea89c fix workflow event trigger 2023-11-26 17:00:37 -06:00
81de857670 protocol_test: split TestPacketEncodeDecode 2023-11-26 16:58:33 -06:00
e8f5e5fc9c protocol_test: added TestDataEncrypt, TestDataDecrypt, TestCreateNewKey 2023-11-26 16:54:22 -06:00
6f55cbbad5 minor renaming of unit-tests workflow 2023-11-26 16:19:43 -06:00
b02c141000 fix workflow 2023-11-25 23:38:41 -06:00
5b78c3dbd4 added entity_test.go 2023-11-25 23:36:23 -06:00
d31723e245 started testing workflow 2023-11-25 23:36:02 -06:00
bb50948935 minor styling fix 2023-11-25 23:15:47 -06:00
d32facf363 swithed to blackbox testing
just because i am lazy
2023-11-25 23:11:19 -06:00
4419260cd0 rename TestPacket -> TestPacketEncodeDecode
also, verify encoded bytes to a sample
2023-11-22 20:04:53 -06:00
9df5a3d0d5 start packet_test.go; minor packet.go refactoring 2023-11-22 18:18:22 -06:00
7d83732e44 genstructs.py: refactor; use match/case statement
- lol, i had no idea python *FINALLY* added a switch/case equivalent.
sadly though, it looks like the generated python bytecode is
nearly identical in performance.
there's no lookup table magic for match/case, and is almost
identical to if/else if/else. it amounts to syntax sugar 😭
2023-11-22 16:02:00 -06:00
7eece044c5 more better db tests; use psql 15, not latest
- our db_test tests now use psql version 15 (which is the same
version our docker-compose file uses) for consistency.
- also added another test, TestDBPlayer
2023-11-22 15:41:31 -06:00
e8f8129b35 fix: SetPlayerInventorySlots actually uses tx now
lol, must've been a typo
2023-11-21 14:13:55 -06:00
f95cc2cae7 test: started internal/db test cases
- we use github.com/bitcomplete/sqltestutil to spin up a postgresql
container to test against
- minor error variable refactoring
2023-11-21 13:58:59 -06:00
459b71a109 fix: Chunks are now goroutine safe
- added Chunk.ForEachEntity()
- refactored SendPacketExclude() to use it
- Chunk.Entities is now Chunk.entities, which is private.
- Chunk.AddEntity() && RemoveEntity() now lock the chunk mutex
2023-11-21 01:49:57 -06:00
06f4a4d33f minor chunk refactoring
- rename GetChunk -> GetChunkPos
- rename SetChunk -> SetChunkPos
2023-11-21 01:36:23 -06:00
3e04103ae4 fix formatting 2023-09-18 21:09:20 -05:00
3559682d18 genstructs.py: generate PacketIDToString()
this will be nice to have for debugging
2023-09-18 20:46:37 -05:00
a78dedcb89 better readme 2023-08-23 18:38:14 -05:00
dcb86e2518 more minor refactoring 2023-08-23 18:37:57 -05:00
458e907c99 moved 'core' to 'internal' 2023-08-23 18:16:24 -05:00
74b68863b1 updated readme 2023-08-23 18:05:03 -05:00
83b664da93 minor refactoring, fixed go-staticcheck warnings 2023-08-23 18:03:14 -05:00
670d4a514c more better CNPeer.Send()
this fixes a race condition where if 2 goroutines try to send a packet at the same time, they could end up being
malformed due to the 2 separate calls to peer.conn.Write().

instead of writing the packet size to peer.conn.Write() directly, we make space in buf for the packet size,
and patch it in place. this lets us get away with only having 1 call to peer.conn.Write() which will ensure that
the full packet is written properly and be goroutine safe :3
2023-08-23 17:38:10 -05:00
7ebe80d6e3 fixed FinishPlayer assigning items to the wrong slots 2023-07-02 17:24:15 -05:00
f27e72d68d send chat packets to *all* players 2023-06-27 22:05:08 -05:00
215e313c43 added chat :D 2023-06-27 21:49:11 -05:00
3559d9ba9b switched NPC autoincremented ID to atomic int 2023-06-27 20:06:51 -05:00
c4325475ed minor renaming 2023-06-27 00:48:17 -05:00
fd41b32b70 added NPCs; added tdata submodule
- use environment variable TDATA_PATH to specify the location of the
  tdata directory
2023-06-27 00:36:02 -05:00
80dc876517 added shard.addEntity() and shard.removeEntity() 2023-06-27 00:11:00 -05:00
c09a6cfd25 fixed sent server time 2023-06-25 18:29:31 -05:00
8f00a0c492 movement.go: added support for basic movement packets
you should be able to view other players and jump around together,
although while testing locally one of the clients would always trigger
the "Some irregularities have been found with your connection to the
server, so your game will be closed" speed check for some reason ???

really not sure, might just be my machine

chunking uhhh works ? kind of, not tested for more than a few seconds
before one of the clients disconnects
2023-06-25 04:27:42 -05:00