Skip to content

Instantly share code, notes, and snippets.

@colin-haber
Created April 23, 2012 17:14
Show Gist options
  • Select an option

  • Save colin-haber/2472370 to your computer and use it in GitHub Desktop.

Select an option

Save colin-haber/2472370 to your computer and use it in GitHub Desktop.
/**
* This file is part of CHAT - The stupid messaging protocol.
* Copyright (C) 2012 Jon Stevens and Colin Haber
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
package com.limyc.chat;
import com.n1nja.semver.Version;
/**
* @author Colin Haber
* @version 0.2.0
* @since 0.2.0
*/
public class CHAT {
public static final Version VERSION = new Version(0, 2, 0);
public static final String PROTOCOL = "CHAT";
public static enum Command {
GENERIC("GEN"),
REGISTER("REG"),
MESSAGE("MSG"),
DISCONNECT("DSC");
private String text;
private Command(String text) {
this.text = text;
}
public String getCommand() {
return this.text;
}
@Override
public String toString() {
return this.getCommand();
}
}
public static enum Status {
GENERIC_SUCCESS("000"),
GENERIC_FAILURE("010"),
GENERIC_INVALID_ID("011"),
GENERIC_INVALID_HEADER("012"),
GENERIC_ERROR("020"),
REGISTER_SUCCESS("100"),
REGISTER_FAILURE("110"),
REGISTER_NAME_TAKEN("111"),
REGISTER_ERROR("120"),
MESSAGE_SUCCESS("200"),
MESSAGE_FAILURE("210"),
MESSAGE_INVALID_ID("211"),
MESSAGE_ERROR("220"),
DISCONNECT_SUCCESS("300"),
DISCONNECT_FAILURE("310"),
DISCONNECT_INVALID_ID("311"),
DISCONNECT_ERROR("320");
private String text;
private Status(String text) {
this.text = text;
}
public String getStatus() {
return this.text;
}
@Override
public String toString() {
return this.getStatus();
}
}
public static String getHeader(Command c) {
return CHAT.PROTOCOL + ":" + c.getCommand() + ":";
}
public static String getHeader(Command c, Status s) {
return CHAT.getHeader(c) + s.getStatus() + ":";
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment