Commit Graph

37 Commits

Author SHA1 Message Date
da8dde9818 Do not dynamically allocate memory in CNSocket::sendPacket()
Also reorder the rapid fire check in MobManager::pcAttackNpcs(), so the
output packet validation happens immediately before the buffer is
initialized, for clarity.
2021-03-04 19:51:43 +01:00
1474ff10ac Slight adjustments to the poll() loop
Recheck the entry at the current index after we remove one. This isn't
strictly necessary, since the next pass will get it anyway.

Using a vector as opposed to our own realloc()'d array means indexing
beyond the size() is undefined behavior, so it's better to be safe.
2020-12-12 01:27:28 +01:00
974941f4fa Close our end of the connection when we receive an EOF
This should/might fix the server's CPU usage spiking to 100%.
2020-12-12 01:27:13 +01:00
Gent S
2834891727 Properly output socket errors on Windows 2020-12-08 17:22:14 -05:00
ada8af0b82 Print informative error messages for socket operations
Windows implementation pending.
2020-12-08 15:23:58 -05:00
86e0b1bc13 EINTR is not crash-worthy
This is how it should have been handled anyway. This fixes a (benign)
race condition when the server is killed, as well as gprof builds.

Also updated tdata.
2020-12-08 20:10:02 +01:00
8ebabac7c0 Various bugfixes
* Fixed Nano stamina not being halved on respawn
* Reverted the default argument to terminate() change because MSVC is
undable to disambiguate the function pointer passed to sigaction()
* Fatal errors during init (like in TableData) can just call exit(1)
directly anyway (missing "OpenFusion: terminated." be damned)
* Switched to a slightly more portable syntax for getting the version
in the Makefile
* We shouldn't join the shard thread in the signal handler because the
thread the signal handler ends up running in is undefined behaviour and
we don't strictly need to join it anyway

Many of these issues were discovered on OpenBSD.
2020-12-06 05:25:23 +01:00
dd6fbfb683 Tweak terminate() slightly
* Gave it a default argument, since we never actually care about it, but
it needs to have it to conform to the signal handler prototype
* Constricted the area locked by activeCrit to only the block that deals
with the connections vector, to lower the chance of a future badly
placed call to terminate() deadlocking the server instead
2020-12-06 02:20:46 +01:00
92307063fc Integrate the monitor's listener socket into the shard's poll()
This removes the need for a separate monitor thread.
2020-12-06 01:44:37 +01:00
53d8cb67ba Set monitor connections to non-blocking
Better to just drop monitor connections when the quality is bad than to
risk blocking the shard thread.
2020-12-05 23:16:09 +01:00
6b257887b7 Use an std::vector for PollFDs instead of handling it manually
Lowered poll() timeout to 50, to fix (work around?) slider stutter.
2020-12-05 22:51:17 +01:00
ec7cba644c Clean up polling logic
* Extracted PollFD manipulation and nonblocking socket configuration
into helper functions
* Replaced the connections list with an unordered_map
* Dynamically grow the number of PollFD structures with realloc()

With these changes done, the server's CPU usage is completely diminished
from its old average of ~47% to ~0.07%, with occasional spikes up to ~14%.
2020-12-05 22:47:50 +01:00
269315ca09 Support for poll() (ie. WSAPoll()) on Windows 2020-12-05 22:47:50 +01:00
661061b4eb Switch to non-blocking sockets + poll(); prepare for Windows logic 2020-12-05 22:47:50 +01:00
3a2b488f33 [WIP] fixed a million bugs and one potential one 2020-12-05 22:47:50 +01:00
721b3f440f [WIP] Switched to poll(), but only on Unix 2020-12-05 22:47:50 +01:00
10534886b8 Cleanup for 1.2.
Cleaned up whitespace, comments, brace style, etc.
Updated tdata reference.
2020-10-19 20:48:57 +02:00
e03da83ff3 Rearranged the codebase a little.
* Deleted empty Player.cpp
* Moved the helper functions from the obsolete CNStructs.cpp into
main.cpp and deleted it
* Renamed CombatManager to MobManager, as that will likely become it's
main focus soon
2020-09-16 21:46:15 +02:00
131997f34f Cleaned up all whitespace issues.
The incantation was: sed -i 's/[ \t]*$//g' src/*.[ch]pp
2020-09-14 16:07:05 +02:00
67d899efe6 Implemented proper validation of variable-length packets.
Also changed output buffer in pcAttackNpcs() from dynamically to
statically allocated. This in itself is temporary as I have a better
idea as to how we can allocate buffers with a bit less boilerplate.
2020-08-28 22:18:28 +02:00
3c43dd0193 Try to transmit FF packets in one go, instead of sending the id first. 2020-08-28 22:18:28 +02:00
6db1a7baf1 removed unnecessary allocation 2020-08-26 14:23:40 -05:00
16c11dada0 Fixed a use-after-free and a memory leak. 2020-08-26 00:09:31 +02:00
16bca39dae added simple timer system to CNShardServer 2020-08-24 16:11:40 -05:00
28ad1a0c25 fix windows support for sockets 2020-08-24 13:23:28 -05:00
55add82843
Merge pull request #32 from dongresource/work
-Wall, #pragma once, nanoSummonHandler() cleanup, verbosity levels
2020-08-23 16:57:58 -05:00
e99feb03d5 Add verbosity levels. 2020-08-23 23:09:31 +02:00
8105d0aa88 properly handle socket errors in recieving packets 2020-08-23 15:09:51 -05:00
51a8cc8bdf Silence -Wall warnings. 2020-08-23 19:19:12 +02:00
94b0dc724e major refactoring 2020-08-22 18:31:09 -05:00
0ff1f74cd3 fixed inet_ntoa warnings 2020-08-22 14:02:58 -05:00
cff382a8ce sets a limit for sendData() 2020-08-21 21:32:22 -05:00
c5efbceca3 added sanity checks for sendPacket() 2020-08-21 19:33:42 -05:00
a0d59419f1 changed non-blocking failure to a socket shutdown 2020-08-19 15:54:44 -05:00
24d30a05bf added heartbeat support 2020-08-18 20:34:39 -05:00
b2325eb308 login server moved to main thread 2020-08-18 19:52:02 -05:00
9d366e3720 inital commit 2020-08-18 15:42:30 -05:00