Skip to content

maxwey/ChatServer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 

Repository files navigation

ChatServer

A chat server that can handle message sending between multiple clients.

A functioning client is also available for you to try/download. See: https://github.com/maxwey/ChatClient

What this is, and what this isn't

Firstly, this is a work in progress; it has not been thoroughly tested by any means, and may not always work.

In addition, the communication protocol used in this program is not a standardized protocol; and their functions (as described below) may not be the same as other more standard protocols.

This program started as a side project, and is no longer my main focus, but I will surely be returning to this every so often to tweak and change things as I learn more.

Lastly, I built this as a place to explore and learn something new. If you have any comments, ideas, questions or suggestions on anything, I would be extremely interested in knowing what you think!

How to use the server

Launch in command line in the format: java ChatServer [-p port_number] [-l] [-g]

-p port_number is the port on which this server will be listening for connetions. Replace port_number with the number of your choice. The default is 58755.

-l flag indicates that the server will log all screen output to a file. File will be autogenerated with a timestamp.

-g flag indicates to the server to launch in no-gui mode. This will make the default standard in and standard out where all console text is shown. This mode is enabled by default when the current machine does not support GUIs (such as many server machines)

Assuming you have a correctly configured network you should see the message "Server ready" printed after the settings. Clients should now be able to connnect to the server via the IP address.

The Admin Commands

Once the server is on, the only way to configure its settings are with the admin commands. Admin commands can be called in 2 ways: By entering the command in the server terminal (keyboard input), or by a properly authorized client (with the ADM code ID; see the client implementation for more details on this subject).

Available Commands & Format

  • ADMIN [USER_NAME] [(y)es|(n)o] - Makes the specified user(s) admins, so that they can access the command list

  • PSWD [PASSWORD] - Sets the password to server. Omiting text after PSWD will remove a pre-exiting password. Only new users will need to authenticate.

  • KICK [USER_NAME] [REASON] - Disconnects specified user(s), and sends [REASON] to indicate why they are being disconnected

  • NOTIFY [MESSAGE] - Shows [MESSAGE] as a server notification to all users.

  • TELL [USER_NAME] [MESSAGE] - Shows [MESSAGE] as a server message to the specified user(s) only.

  • QUIT (MESSAGE) - Closes the server program. If specified, the optional (MESSAGE) is sent to all users.

  • LIST - Lists all connected users and their IP addresses

  • HELP - Lists all available commands

Where [USER_NAME] is the name, or names (delimited by a , character) of the target users. The single character * can also be used to indicate all connected users.

Passwords can be any character sequence, but must begin and end with non-whitespace characters. Entering ' test ' as a password will result in 'test' being used as the server password. This behavior is intended to avoid accidentally setting the password to have beginning and trailing spaces as they are not always easily identified.

FOR NO-GUI MODE: Entering the \ character into the console will toggle pausing all output. This is inteded to allow for an easier time entering and reading the commands sent. This mode is ideal when the output is causing input to become unreadable. The output will become unpaused by simply sending another \

Notes about Code IDs/Commands

Every communication between the server and the client start with a 3 letter ID code to inidcate the nature of the request/or what the following information indicates. The 3 letter code is immediately followed by the content (if applicable). There is no extra whitespace between the ID code and the following message. All communications are terminated with a null character ('\0') to deliminate when the message has been completely received. Some codes require multiple pieces of information to be sent; these pieces are delimited by the '\3' character.

  • NCR - New Connection Request: sent by client to initiate a connection. The message is immediately followed by a LEGAL username (1-10 characters comprised of: 'A'-'Z', 'a'-'z', or '_'), a separator character ('\3') and a password. The password field is ignored if the server password isnt set.
  • CON - Connected: sent by the server to the client to acknowledge and confirm the connection request. No additional data is included
  • NCN - Not Connected: sent by the server to the client to indicate that the client was not able to connect with the given information.
  • DSC - Disconnect: sent by client or server to "politely" indicate that the program will disconnect. A reason or message can optionally follow.
  • SND - Send Message: sent by the client to indicate a new message to be sent to the other users. The data that follows it is the message to be sent
  • MSG - Forward Message: sent by the server to the clients to indicate a new message. The data that follows it is the username of the sender, a separator character ('\3') and the message
  • NOT - Server notification: sent by the server to the clients with a message from the server.
  • ADM - Admin Command: sent by client to server to issue an admin command. (The user must have permission to use the admin commands) The message that follows the ADM command will be executed
  • RSP - Server response: optionally sent by server following an ADM command with the response text/output.

NOTE: the following serve to notifiy of an issue. The server and clients should be able to recover from an ERC/ERS regardless of their nature. The ERC and ERS may be followed by additional text to indicate where/what the error is.

ERC - Error Client: sent by the server to the client to indicate that something the client has committed an Error (sent bad data)

ERS - Error Server: sent by the client to the server to indicate that something the server has committed an Error (sent bad data)

Future Work

  • Reading server properties from a file such as password, port settings, etc.
  • Logging settings to modify how much is logged and saved (currently, EVERYTHING is saved... useful for debugging, not so much from a privacy standpoint)
  • Admin specific password: server has 2 passwords, one for users and one for admins. Logging in with a valid admin password grants admin access... this might also be paired with an IP address whitelisting... I'm still unsure how to best implement this
  • Repeated login failure detection -- attempting to prevent a brute-force attack to admin account.
  • Banning people?

About

A chat server that can handle message sending between multiple clients.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages