//   Course Number: COSC 650 Data Comm/Networks
//      Class Name: ChatMessage.java
//  Project Number: 2
//         Authors: Brian Hoffman
//                  Mike McKinney
//                  Javier Carrasco
//     Description: This class is used to represents all of the messages that 
//                  our chat client can send and receive through the socket. A
//                  chat message object contains the following fields: type,
//                  sender, chatroom, and message. The type field can take the 
//                  values of admin or standard and indicates if the message 
//                  contains instructions for the server (admin) or a message 
//                  that should be passed to all participants in the provided 
//                  chatroom (standard). The sender field gives the userName of 
//                  the participant sending the message and the chatroom field
//                  says what room it should be broadcast to. A chatroom value 
//                  of -1 is used for admin messages. Finally, the message field
//                  is a string that contains the message itself. Standard
//                  messages are simple passed on as is by the server while 
//                  admin messages are parsed for instructions. For a list of 
//                  possible admin message strings see below.


// Listing of Message Types
// TYPE             Purpose
// addClient        This message is sent by a client upon login to tell the
//                  server to add the client whose name is provided in the 
//                  sender field to the server's list. The chatroom and message
//                  fields are "".
//
// endClient        Sent by client to indicate that it is closing and should be
//                  removed from the server's list and the connection closed.
//                  The sender field contains the username and the chatroom and 
//                  message fields are "".
//
// acceptClient     Sent by the server to indicate that the connection has been
//                  accepted and provide the list of available chatrooms. The 
//                  sender and chatroom strings are "" while the message holds 
//                  a comma separated list of chatroom names.
//
// denyClient      Sent by the server to indicate that the connection is refused.
//                 All fields but the type are set to "".
//
// endServer       Sent by the server to indicate that it is being shut down and
//                 that the clients should act appropriately. All fields but the
//                 type are set to "".
//
// joinRoom        Sent by the client to indicate the desire to join the room
//                 indicated in the chatroom field. The sender field holds the 
//                 client's username and the message field is "".
//
// roomAccept      Sent by the server to indicate that the client has joined the
//                 room given in the chatroom field. The sender field is "" and
//                 the message field holds a comma separated list of participants.
//                 The first participant must be the rooms owner. Upon receipt
//                 the client must open a chat dialog for the given room.
//
// roomDeny        Sent by the server to indicate that the client's request to
//                 join the room given in the chatroom field has been denied. All
//                 other fields are set to "". The client will automatically put
//                 up a dialog indicating the failure.
//
// leaveRoom       Sent by the client to indicate that the user in the sender 
//                 field has exited the room given in the chatroom field. The
//                 message field is set to "".
//
// endRoom         Sent by the server when the owner of the room in the chatroom
//                 field has left that room, and thus, forced the room to close.
//                 Other than the type and chatroom field, all fields are set to
//                 "".
//
// particAdd       Sent by the server to all participants in a room to notify of 
//                 a new user's acceptance into a room. The sender will be "". 
//                 The chatroom field will be the name of the room. The message 
//                 will be the name of the new user.
//
// requestPrivate  This message is sent to the server by a client who wishes to 
//                 request a private chatroom. The sender field holds the name 
//                 of the client requesting the room and the message field holds
//                 the name of the other participant. The chatroom field is ""
//                 to start with. Upon receipt the server creates a room in a
//                 separate temporary list with both the requester and given
//                 username as participants and the requester set as the owner.
//                 The server then adds the newly created room name to the 
//                 chatroom field and forwards it to the other client for 
//                 acceptance.
//
// acceptPrivate  Indicates that the client sending this message agrees to be in
//                the private chatroom with the provided temporary names. Upon
//                receipt the server sends a roomAccept message to both particiants
//                forcing them to open chat windows. See above.
// 
// denyPrivate    This message is sent by the denying client to the server to 
//                indicate its refusal of the room. The sender fields is set to 
//                the name of the refusing client, the chatroom field to the 
//                name of the refused room, and the message field to "". Upon 
//                receipt, the server sends this message onto the requesting 
//                client and also cleans up the temporary room.
//
// createRoom     Sent by a client to indicate that it wants to create a new room
//                with its user as the owner. The name of the new room is given 
//                in the chatroom field, the name of the user in the sender field, 
//                and the message field is blank.
//
// denyRoom       Returned by the server to indicate that the room was not
//                accepted due to a conflicting name. The sender and message
//                fields are "" and the chatroom field is the ofending name.
//
// roomOverflow   Returned by the server to indicate that it has too many open
//                rooms and cannot accept a new one 
//
// addRoom        Broadcast to all participants to indicate that a new room given 
//                in the chatroom field has been created with the owner given in 
//                the message field. If the owner is the current client's name, 
//                it must popup a chat dialog and add the room to its list. All
//                other clients just add the room to their list.
//
// bootUser       Message sent by the owner of a chatroom to remove a participant
//                from the room. When sent from the client the message's chatroom 
//                field comtains the room in question, the sender field contains 
//                the username of the booter, and the message field contains the
//                username of the one to be booted. The server responds by passing
//                this message along to the victim and by removing that person from
//                the room. This last step sends a leaveRoom message to all clients,
//                in the room, including the booter, with the name of the person
//                to be booted. 
//
// default        Broadcast the message to all in the room given by the chatroom
//                field. The sender field holds the name of the sender and the 
//                message field holds the text of the actual message.
                                         
// Java Core Packages
import java.io.*;
import java.net.*;

public class ChatMessage implements Serializable
{ 
    private String type;
    private String sender;
    private String chatroom;
    private String message;
    
    // ------------------------------------------------------------------------
    // default constructor
    //------------------------------------------------------------------------- 
    public ChatMessage()
    {
        type = "admin";
        sender = "nobody";
        chatroom = "";
        message = "";
    }
    
    // ------------------------------------------------------------------------
    // constructor
    //------------------------------------------------------------------------- 
    public ChatMessage(String t, String s, String chatRm, String msg)
    {
        type = t;
        sender = s;
        chatroom = chatRm;
        message = msg;
    }
    
    // ------------------------------------------------------------------------
    // get functions 
    //------------------------------------------------------------------------- 
    public String getType() { return type; }
    public String getSender() { return sender; }
    public String getRoomName() { return chatroom; }
    public String getMsg() { return message; }
    
    // ------------------------------------------------------------------------
    // set functions 
    //------------------------------------------------------------------------- 
    public void setType(String t) { type = t; }
    public void setSender(String s) { sender = s; }
    public void setChatRmId(String id) { chatroom = id; }
    public void setMsg(String m) { message = m; }   
}