This is an old retired project, so the game is not live to play, but I have posted the development blog here for historical purposes.


Initial Statement (May 8, 2019):


I haven't posted an update since my documentation of my Java multiplayer game, so here's what happened: I got bored. This project essentially became the same thing I was doing when I first tried to make a 2D game in Java, and I've been working with Java so long that I did not feel like that was going to improve my programming skills. Also, running Java applications feels too slow to me now. But, I still want to make a multiplayer game from scratch for the sake of completing my personal project.

So, I decided to restart my entire game and write it in C instead of Java. I realize that C++ comes with design principles that would be better suited for this project than plain C, but I have a strong desire to get familiar with the C language, so that's what I picked.

Update Pack 1: Multiplayer 1.0


Updates (expand)

Tuesday, July 16, 2019

I’ve been kind of busy lately, so I haven’t posted an update or uploaded my progress to GitHub in a while, but I’ve gotten a good amount of work done. In fact, this package of updates contains the FIRST instance of what could actually be considered a multiplayer game! As of now, there is little to do besides walk around on a tiny map and see other players who are also connected, but getting the rendering of other players done was an obstacle that, once cleared, allowed me to bring this world to life. I never even reached this point when I was doing my game in Java, so it was  fun brainstorming concepts to support a dynamic multiplayer world and then coding them into the real thing.

 

Multiplayer Support

– store online players in a hash table with their current map section as the key and their player ID as the value
– server ability to tell other clients about the existence and location of your player
– client ability to request the server to send info of all players in current map section
     – requested when your player logs in
     – requested when your player enters a new map section
– server sends all players in your map section an update on your coordinates whenever you send a movement request
– client support for rendering other players when receiving a notification of their existence from the server
– your player has a different appearance than all other players on your client
– server ability to tell other clients about the “absence” of your player
– clients respond to player absence notifications by no longer rendering that player
– absence notifications are sent to everyone in a map section when a player leaves that sesction
– absence notifications are sent when a player disconnects from the server
– players are removed from the global hash table when disconnecting
– clear data of players to be rendered on the client when entering a new map section
     – this fixed a bug where players from old map sections would still be rendered in your new area, even though they weren’t actually there

Data Structures:

– wrote my own hash table for processsing data
– added ability to store duplicate keys in the hash table
– added ability to remove specific (key,value) pairs from the hash table
– wrote my own “mutable list”
– mutable list starts at a set “small” size and resizes when it becomes full
      ~ resizing is not currently implemented, so it’s just a list that can hold 20 elements
– ability to iterate thru the items of a mutable list

Maps:

– added loading tiles from image files
– added cache of loaded tile images to be re-used in rendering instead of loading an image each time it needs to be rendered
– tile image files are named using base-36 numbers
– map is organized into “sections”, each of which is represented by a “map string” that is stored in data files on the server-side
– map section is an integer computed from player’s absolute coordinates
– server retrieves data from the file of the associated map section and sends the map string to the client
– client ability to process and render the map from its current map string
– client sends server a request for map data whenever it needs to refresh the map
     – when logging in
     – when moving off-screen into a new map section
– sections with no map data render as an astral “void” of starry sky
– ability to recognize tiles as walkable or unwalkable
     ~ will reform this to a more efficient method in the future
– prevented walking into unwalkable tiles

Misc:

– remove players from the game when their respective client disconnects from the server
     – resulted in an accurate player count
– added mutex for thread-control in the game thread of the server
     – this fixed a server-side segmentation fault when dealing with hashing players into their map sections, resulting in a much stabler server
– fixed a rare server issue that occasionally added random characters to the end of a player’s username, resulting in the server crashing when trying to find the respective player data file

Current  To-Do List:

– add more chars to keyboard in client
– recycle old player ids
– support to kick clients from server-side
– stop messages from being processed from kicked players
– prevent login if player is already logged in (lol)
– issues logging out that can cause client to crash
– readme for how to run
– organize and document code
– make the map move around the player
– reduce cpu usage
– bugs causing the client to crash (these happen randomly)
     – using the logout button sometimes triggers a segmentation fualt
     – entering the game sometimes triggers a segmentation fault
     ~ most likely needs a mutex to fix
– improve the loaded tile image cache mechanics
     – right now it will fail if the cache gets full
     – need to add tile “unloading”
     – perhaps a splay tree would be useful for this
– add the resizing mechanic to mutable lists

Update Pack 2: User Interface, Map Building, Chat


Updates (expand)

Thursday, August 1, 2019

I actually finished 90% of this update pack shortly after I released my first update pack, but I stalled a lot getting the remaining details finished. Anyway, this update pack brings some features that make the game feel just a little bit more like an actual game. The main three features I’ve added are user interfaces, an in-game map editor, and public chat. Here is a video demonstrating these:

 

Below is a mostly-complete list of updates that went into this update pack. I didn’t add exact dates because I forgot to write most of this down as I was doing it, so this list was mainly constructed from my own memory.

 

Changes Since Previous Update Pack:

– Sidebar Interfaces

  • drew icons for each “tab” of the interface
  • added the settings tab
  • displays button to toggle map editing
  • added logout tab which instantly logs you out when clicked

– Control Panel Interface

  • displays various option buttons when you may need them

– Info Box Interface

  • displays text notifications in-game
  • server-side support for sending a message to the player’s info box
  • info box messages are pushed upward on-screen so that newest messages are listed at the bottom

– In-Game Map Builder

  • added map editor state to control panel
  • added “toggle map editor” button to settings menu
  • added button to look up tile data
  • enter base-36 number for the tile you wish to add
  • click on a tile on the map to replace it with your selected tile
  • image of the chosen tile follows your cursor
  • support for click and drag for faster map drawing
  • added button to send map to server
    • this updates the map data on the server to what you created in map editor mode

– Public Chat

  • added text field to client game state that appends text when typing
  • press enter to send your current text field as a public chat
  • public chat sends to server, then is broadcasted to all players in your map section
  • when client is notified of a player’s public chat, the message is displayed to the info box

– Sprite Cache for Client

  • attempts to load all sprites into one place, then use them as needed
    • this seems to fix an occasional issue where an image is loaded and its pixels are completely screwed up

– Miscellaneous

  • fixed a client crash on login by properly initializing the client’s mapstring

 

 

To-Do List Relevant to Update Pack 2:

– Map

  • map stops loading correctly when entering negative coordinates
  • client segmentation fault occurs when trying to log in at the lowest positive-coordinate map section when other players are in the same section

– Menu Interface

  • add player info menu
    • display player’s coordinates
    • display player’s account status (player, developer, owner, etc.)
  • add logout menu
    • “Thanks for playing” message
    • button to log out (instead of instantly logging out when trying to open the logout menu)

– Info Box Interface

  • touch up logic so things are more organized
  • add support for scrolling through previous messages

– Login Protocol

  • make sure everything happens in the proper order and can’t be broken by lack of proper thread synchronization
  • (maybe) add a queue of messages to process

– Stability and Bug Fixes

  • fix client deadlock when server shuts down
  • fix client crash when sending map data to server after map editing
  • fix client segmentation fault that sometimes occurs on login
  • fix client issue that occasionally deletes a currently-loaded sprite
  • add all client sprites to global sprite cache so no weird pixel bugs occur
  • fix server segmentation fault that rarely occurs when players log out
  • fix server segmentation fault that rarely occurs when players log in

Above you can view demo videos of two different packages of updates in this project's history.

Click below to see a cumulative list of all updates done to this project.


View All Updates (expand)

ALL Updates

UPDATE LOG

 


 


        TODO:
        
        - add more chars to keyboard in client
        
        - recycle old player ids
        
        - support to kick clients from server-side
        
        - stop messages from being processed from kicked players
        
        - prevent login if player is already logged in (lol)
        
        - issues logging out that can cause client to crash
        
        - readme for how to run
        
        - organize and document code
        
        - make the map move around the player
        
        - reduce cpu usage
        
        - bugs causing the client to crash (these happen randomly)
        
        - using the logout button sometimes triggers a segmentation fualt
        
        - entering the game sometimes triggers a segmentation fault
        
        ~ most likely needs a mutex to fix
        
        - improve the loaded tile image cache mechanics
        
        - right now it will fail if the cache gets full
        
        - need to add tile "unloading"
        
        - perhaps a splay tree would be useful for this
        
         
        
        
        ~~~~~~~~~~~~~~~~~~~~~~~~~
        
        July (exact dates unknown)
        
        ~~~~~~~~~~~~~~~~~~~~~~~~~
        
         
        
        
        Sidebar Interfaces
        
        - drew icons for each “tab” of the interface
        
        - added the settings tab
        
        - displays button to toggle map editing
        
        - added logout tab which instantly logs you out when clicked
        
         
        
        
        Control Panel Interface
        
        - displays various option buttons when you may need them
        
         
        
        
        Info Box Interface
        
        - displays text notifications in-game
        
        - server-side support for sending a message to the player’s info box
        
        - info box messages are pushed upward on-screen so that newest messages are listed at the bottom
        
         
        
        
        In-Game Map Builder
        
        - added map editor state to control panel
        
        - added "toggle map editor" button to settings menu
        
        - added button to look up tile data
        
        - enter base-36 number for the tile you wish to add
        
        - click on a tile on the map to replace it with your selected tile
        
        - image of the chosen tile follows your cursor
        
        - support for click and drag for faster map drawing
        
        - added button to send map to server
        
        - this updates the map data on the server to what you created in map editor mode
        
         
        
        
        Public Chat
        
        - added text field to client game state that appends text when typing
        
        - press enter to send your current text field as a public chat
        
        - public chat sends to server, then is broadcasted to all players in your map section
        
        - when client is notified of a player’s public chat, the message is displayed to the info box
        
         
        
        
        Sprite Cache for Client
        
        - attempts to load all sprites into one place, then use them as needed
        
        - this seems to fix an occasional issue where an image is loaded and its pixels are completely screwed up
        
         
        
        
        Miscellaneous
        
        - fixed a client crash on login by properly initializing the client’s mapstring
        
         
        
        
         
        
        
         
        
        
        Multiplayer Support
        
        - store online players in a hash table with their current map section as the key and their player ID as the value
        
        - server ability to tell other clients about the existence and location of your player
        
        - client ability to request the server to send info of all players in current map section
        
        - requested when your player logs in
        
        - requested when your player enters a new map section
        
        - server sends all players in your map section an update on your coordinates whenever you send a movement request
        
        - client support for rendering other players when receiving a notification of their existence from the server
        
        - your player has a different appearance than all other players on your client
        
        - server ability to tell other clients about the "absence" of your player
        
        - clients respond to player absence notifications by no longer rendering that player
        
        - absence notifications are sent to everyone in a map section when a player leaves that sesction
        
        - absence notifications are sent when a player disconnects from the server
        
        - players are removed from the global hash table when disconnecting
        
        - clear data of players to be rendered on the client when entering a new map section
        
        - this fixed a bug where players from old map sections would still be rendered in your new area, even though they weren't actually there
        
         
        
        
         
        
        
        Data Structures:
        
        - wrote my own hash table for processsing data
        
        - added ability to store duplicate keys in the hash table
        
        - added ability to remove specific (key,value) pairs from the hash table
        
        - wrote my own "mutable list"
        
        - mutable list starts at a set "small" size and resizes when it becomes full
        
        ~ resizing is not currently implemented, so it's just a list that can hold 20 elements
        
        - ability to iterate thru the items of a mutable list
        
         
        
        
         
        
        
        Maps:
        
        - added loading tiles from image files
        
        - added cache of loaded tile images to be re-used in rendering instead of loading an image each time it needs to be rendered
        
        - tile image files are named using base-36 numbers
        
        - map is organized into "sections", each of which is represented by a "map string" that is stored in data files on the server-side
        
        - map section is an integer computed from player's absolute coordinates
        
        - server retrieves data from the file of the associated map section and sends the map string to the client
        
        - client ability to process and render the map from its current map string
        
        - client sends server a request for map data whenever it needs to refresh the map
        
        - when logging in
        
        - when moving off-screen into a new map section
        
        - sections with no map data render as an astral "void" of starry sky
        
        - ability to recognize tiles as walkable or unwalkable
        
        ~ will reform this to a more efficient method in the future
        
        - prevented walking into unwalkable tiles
        
         
        
        
         
        
        
         
        
        
        Misc:
        
        - remove players from the game when their respective client disconnects from the server
        
        - resulted in an accurate player count
        
        - added mutex for thread-control in the game thread of the server
        
        - this fixed a server-side segmentation fault when dealing with hashing players into their map sections, resulting in a much stabler server
        
        - fixed a rare server issue that occasionally added random characters to the end of a player's username, resulting in the server crashing when trying to find the respective player data file
        
         
        
        
        ~~~
        
         
        
        
         
        
        
        Thursday May 30 2019
        
        - wrote the logout protocol to remove players from the game when receiving logout requests
        
        - added logout button to game state
        
        - rewrote the communication protocol between client and server for more uniform packet sending
        
        - rewrote the login protocol under the new communication protocol
        
        - rewrote updating coordinates under the new communication protocol
        
         
        
        
        Wednesday May 22 2019
        
        - refined player movement
        
        - fixed more bugs in sending several messages to/from server/client
        
         
        
        
        Tuesday May 21 2019
        
        - added server-side support for walking around
        
        - player coordinates are saved when changed and loaded upon login
        
        - client now reflects player's server-side coordinates
        
        - added first draft of client-server communication protocol
        
        - client keyboard no longer types blank spaces for unsupported characters
        
         
        
        
        Monday May 20 2019
        
        - added the game state
        
        - gave client appropriate behavior to responses to login requests
        
            - loading screen while waiting for request to complete
        
            - destroy login state and load game state upon successful login
        
        - display the player at the proper coordinates in client game state
        
        - ability to update player coordinates in game state
        
         
        
        
        Sunday May 19 2019
        
        - fixed issues with sending and receiving messages to/from client
        
            - buffers were glitchy and only sending parts of messages
        
            - sometimes messages would not be sent at all
        
            - sometimes extra space was added to received messages in client
        
            - sending/receiving messages now fits the desired text perfectly
        
         
        
        
        Thursday May 16 2019
        
        - added partial support for login requests
        
            - client sends username and password pairs to server using a flag to let the server know the message is a login request
        
            - server recognizes login requests and replies to them
        
        - added login buttons; one to send username and password fields to server, one to exit the client
        
        - added support for GUI to signal the networking thread of client to send messages to server
        
        - added click detection for buttons
        
        - added support for buttons
        
        - fixed random segmentation fault that occurred because I somehow had two copies of the SDL2 library installed, one of which was corrupted
        
         
        
        
         
        
        
        Wednesday May 15 2019
        
        - support for pressing 'tab' key to alternate between which text field you're typing in
        
        - added two dynamic text fields to login state; one for username, one for password
        
        - added login state to client
        
        - added the alphabet, numbers, and spaces to characters that can be rendered to text fields
        
        - created rough draft background for login screen
        
         
        
        
         
        
        
        Tuesday May 14 2019
        
        - added the Arial font
        
        - added the SDL_image library to create support for loading PNG images
        
        - added the SDL_ttf library to create support for fonts and displaying text
        
        - added support for dynamic text fields
        
        - added support for hardware events in client GUI
        
            - clicking
        
            - scrolling
        
            - mouse movement
        
            - typing