activepk
April 02, 2020, 04:07:54 pm
Welcome, Guest. Please login or register.

Login with username, password and session length
News: welcome to activepkscape!
 
  Home Help Search Arcade Staff List Login Register  

new code


Pages: [1]
  Print  
Author Topic: new code  (Read 44 times)
tyler
Administrator
Newbie
*****
Posts: 12



View Profile
« on: January 22, 2008, 04:52:33 pm »

adding clan chat to server my code i know it workds i had sum1 test it


_________________________________________________________________________________________
ADDING CLAN CHAT TO SERVER!!!
Make a  .java and name it
clanChat.java
___________________________________________________________________________________________________________________________
then add this to it

import java.io.*;
import java.net.*;

public class clanChat {

public boolean sortChat(String str, int player) {
boolean usd = false;
if(str.startsWith("/join")) {
joinChat(str, player);
} else if(str.startsWith("/make")) {
makeChat(str, player);
} else if(str.startsWith("/leave")) {
leaveChat(str, player);
} else if(str.startsWith("/forbid")) {
forbidChat(str, player);
} else if(str.startsWith("/owner")) {
chatOwner(player);
} else if(str.startsWith("/remove")) {
removeChat(str, player);
} else if(str.startsWith("/list")) {
listChats(str, player);
} else if(!str.startsWith("/")) {
return false;
} else {
displayChat(str, player); return true;
} return false;
}
public void displayChat(String disp, int player) {
int s = disp.length()-5;
String playerName = server.playerHandler.players[player].playerName;
if(server.playerHandler.players[player].clanChan == "none") {
client z = (client) server.playerHandler.players[player];
z.sendMessage("** You are not in a clan channel. :clan");
} else
if(!cmdChat(disp) && server.playerHandler.players[player].clanChan != "none") {
disp = disp.substring(1,s);
System.out.println("[CLAN] "+player+"... "+disp);
for(int c = 0; c < server.playerHandler.maxPlayers; c++) {
if(server.playerHandler.players[c] != null && server.playerHandler.players[player].clanChan != "none") {
if(server.playerHandler.players[player].clanChan.equalsIgnoreCase(server.playerHandler.players[c].clanChan)) {
client q = (client) server.playerHandler.players[c];
q.sendMessage("[Clan]"+playerName+"... "+disp+":clan");
}
}
}
}
}
public void joinChat(String chat, int player) {
client p = (client) server.playerHandler.players[player];
int S = chat.length()-5; String clanChat = chat.substring(6, S);
if(!chatExists(chat)) {
p.sendMessage("** A clan with the name of '"+clanChat+"' does not exist. :clan");
} else
if(forbiddenChat(chat)) {
p.sendMessage("** The name '"+clanChat+"' is a forbidden chat name. :clan");
} else
if(chatExists(chat) && !forbiddenChat(chat)) {
p.clanChan = clanChat;
for(int c = 0; c < server.playerHandler.maxPlayers; c++) {
if(server.playerHandler.players[c] != null && server.playerHandler.players[player].clanChan != "none") {
if(server.playerHandler.players[player].clanChan.equalsIgnoreCase(server.playerHandler.players[c].clanChan)) {
client x = (client) server.playerHandler.players[c];
x.sendMessage("[Clan]"+p.playerName+" has joined the channel. :clan");
}
}
}

}
}
public void makeChat(String chat, int player) {
client p = (client) server.playerHandler.players[player];
int S = chat.length()-5; String newClan = chat.substring(6, S); checkFolder();
if(newClan.length() < 5) {
p.sendMessage("** A clan channel must have a name of 5 characters or more. :clan");
} else
if(chatExists(chat)) {
p.sendMessage("** A clan with the name of '"+newClan+"' already exists. Try a new name. :clan");
} else
if(forbiddenChat(chat)) {
p.sendMessage("** The name '"+newClan+"' is a forbidden chat name. :clan");
} else
if(clanOwner(player)) {
p.sendMessage("** You are already in possession of a clan channel. You may only have one. :clan");
} else
if(!chatExists(chat) && !forbiddenChat(chat) && !clanOwner(player)) {
try {
BufferedWriter c = new BufferedWriter(new FileWriter("./Clan Chat/clan_chat.srv", true));
c.write("# DONT REMOVE THIS LINE #"); c.newLine();
c.write("# DONT REMOVE THIS LINE #"); c.newLine();
c.write(newClan+" :O: "+server.playerHandler.players[player].playerName); c.newLine();
c.write("# DONT REMOVE THIS LINE #"); c.newLine();
c.write("# DONT REMOVE THIS LINE #"); c.newLine();
c.flush();
} catch(IOException IOE) { }
p.sendMessage("** You have successfully created the clan chat for '"+newClan+"'. :clan");
p.sendMessage("** You may join the chat by typing '/join "+newClan+"'. :clan");
}
}
public boolean chatExists(String clan) {
try {
checkFolder();
BufferedReader srv = new BufferedReader(new FileReader("./Clan Chat/clan_chat.srv"));
String data = new String();
int el = clan.length()-5;
clan = clan.substring(6, el); clan = clan.substring(0,clan.length());
while ((data = srv.readLine()) != null) {
if(data.startsWith(clan+" :O:")) {
return true;
}
if(data.startsWith(new String(clan.substring(2)))) {
return true;
}
}
} catch(IOException IOE) { }
return false;
}
public boolean clanOwner(int player) {
try {
checkFolder();
BufferedReader srv = new BufferedReader(new FileReader("./Clan Chat/clan_chat.srv"));
String data = new String();
while ((data = srv.readLine()) != null) {
if(data.endsWith(server.playerHandler.players[player].playerName)) {
return true;
}
}
} catch(IOException IOE) { }
return false;
}
public void chatOwner(int player) {
try {
checkFolder();
BufferedReader srv = new BufferedReader(new FileReader("./Clan Chat/clan_chat.srv"));
String data = new String();
clanOwner = "none";
String clan = server.playerHandler.players[player].clanChan;
while ((data = srv.readLine()) != null) {
client h = (client) server.playerHandler.players[player];
if(data.startsWith(clan+" :O:")) {
clanOwner = data.substring(clan.length()+5);
}
}
} catch(IOException IOE) { }
if(server.playerHandler.players[player].clanChan.equalsIgnoreCase("none")) {
client y = (client) server.playerHandler.players[player];
y.sendMessage("** You must be on a clan channel to use this feature. :clan");
}
}
public void checkFolder() {
File Clan_Chat = new File("./Clan Chat/");
if(!Clan_Chat.isDirectory()) {
Clan_Chat.mkdir();
}
}
public void listChats(String chat, int player) {
client p = (client) server.playerHandler.players[player];
p.clearQuestInterface(); int maxx = 0;
p.sendQuest("@dre@--Clan Chat List", 8144);
for(int c = 0; c < server.playerHandler.maxPlayers; c++) {
if(server.playerHandler.players[c] != null && server.playerHandler.players[c].clanChan != "none") {
p.sendQuest("@dre@--Clan Chat List", 8144); maxx++;
p.sendQuest("@whi@ Users In Clan Chat Rooms: "+countChat(), 8145);
p.sendQuest("@dbl@"+server.playerHandler.players[c].playerName+" is on '"+server.playerHandler.players[c].clanChan+"'.", 8147+c);
}
}
p.sendQuestSomething(8143);
p.showInterface(8134);
p.flushOutStream();
}
public int countChat() {
int counted = 0;
for(int c = 0; c < server.playerHandler.maxPlayers; c++) {
if(server.playerHandler.players[c] != null && server.playerHandler.players[c].clanChan != "none") {
counted++;
}
}
return counted;
}
public boolean cmdChat(String cmd) {
for(int i = 0; i < CMDs.length; i++) {
if(cmd.startsWith("/"+CMDs)) {
return true;
}
}
return false;
}
public void leaveChat(String chat, int player) {
client pl = (client) server.playerHandler.players[player];
for(int c = 0; c < server.playerHandler.maxPlayers; c++) {
if(server.playerHandler.players[c] != null && server.playerHandler.players[player].clanChan != "none") {
if(server.playerHandler.players[player].clanChan.equalsIgnoreCase(server.playerHandler.players[c].clanChan)) {
client x = (client) server.playerHandler.players[c];
x.sendMessage("[Clan]"+pl.playerName+" has left the channel. :clan");
}
}
}
server.playerHandler.players[player].clanChan = "none";
}
public void forbidChat(String chat, int player) {
client p = (client) server.playerHandler.players[player];
if(p.playerRights >= 1) {
int S = chat.length()-5; String chan = chat.substring(8, S); checkFolder();
try {
BufferedWriter bc = new BufferedWriter(new FileWriter("./Clan Chat/forbid_chat.fbd", true));
bc.write(chan); bc.newLine(); bc.flush();
} catch(IOException IOE) { }
p.sendMessage("** You have successfully forbidden the channel '"+chan+"'. :clan");
} else
if(p.playerRights < 1) {
p.sendMessage("** You must have rights of one or higher to forbid a channel. :clan");
}
}
public boolean forbiddenChat(String chat) {
try {
BufferedReader fbd = new BufferedReader(new FileReader("./Clan Chat/forbid_chat.fbd"));
String data = new String();
int fb = chat.length()-5;
chat = chat.substring(6, fb);
while ((data = fbd.readLine()) != null) {
if(chat.equalsIgnoreCase(data)) {
return true;
}
}
} catch(IOException IOE) { }
return false;
}
public boolean ownsChat(String clan, int player) {
checkFolder();
try {
BufferedReader cp = new BufferedReader(new FileReader("./Clan Chat/clan_chat.srv"));
String data; while((data = cp.readLine()) != null) {
if(data.startsWith(clan+" :O:")) {
String ownsClan = data.substring(clan.length()+5);
if(ownsClan.equalsIgnoreCase(server.playerHandler.players[player].playerName)) {
return true;
}
}
}
} catch(IOException IOE) { }
return false;
}
/*public void removeChat(String clan, int player) {
checkFolder();
new File("./Clan Chat/TEMP_0").delete(); new File("./Clan Chat/TEMP_1").delete();
String chat = clan;
clan = clan.substring(Cool;
int b = clan.length()-5;
clan = clan.substring(0,b);
client vv = (client) server.playerHandler.players[player];
if(!chatExists(chat)) { vv.sendMessage("** A chat with this name does not exist. :clan"); } else
if(vv.playerRights < 1 && !ownsChat(clan, player)) { vv.sendMessage("** You must be the owner or have mod status to remove a channel. :clan"); } else
if(!ownsChat(clan, player)) { vv.sendMessage("** You must be the owner of the channel to remove it. :clan"); } else
if(ownsChat(clan, player) || vv.playerRights > 1) {
if(us) { vv.sendMessage("** A channel is currently being removed. Try again in a few seconds. :clan"); } else
if(!us) { us = true;
try {
BufferedReader srv = new BufferedReader(new FileReader("./Clan Chat/clan_chat.srv"));
String data; int line = 0;
while((data = srv.readLine()) != null) { line++;
if(data.startsWith(clan+" :O:")) {
wo = line;
} if(line > wo) {
writeTemp(data, "./Clan Chat/TEMP_1/", 0);
}
}
} catch(IOException IOE) { }
try {
BufferedReader srv = new BufferedReader(new FileReader("./Clan Chat/clan_chat.srv"));
String data; int line = 0;
while((data = srv.readLine()) != null) { line++;
if(line < wo) {
writeTemp(data, "./Clan Chat/TEMP_0", 0);
}
}
} catch(IOException IOE) { }
try {
BufferedReader t = new BufferedReader(new FileReader("./Clan Chat/TEMP_1"));
String data;
while((data = t.readLine()) != null) {
writeTemp(data, "./Clan Chat/TEMP_0", 0);
}
} catch(IOException IOE) { }
try {
FileReader in = new FileReader(new File("./Clan Chat/TEMP_0"));
FileWriter out = new FileWriter(new File("./Clan Chat/clan_chat.srv"));
int fileByte;
while ((fileByte = in.read()) != -1)
out.write(fileByte);
in.close();
out.close();
} catch(IOException ioe) { }
us = false;
}
}
}*/
public void removeChat(String clan, int player) {
checkFolder(); client vv = (client) server.playerHandler.players[player];
String chat = clan; boolean scs = false;
clan = clan.substring(Cool; String[] clans = {""};
int b = clan.length()-5; clan = clan.substring(0,b);
if(!chatExists(chat)) { vv.sendMessage("** A chat with this name does not exist. :clan"); } else
if(vv.playerRights < 1 && !ownsChat(clan, player)) { vv.sendMessage("** You must be the owner or have mod status to remove a channel. :clan"); } else
if(!ownsChat(clan, player)) { vv.sendMessage("** You must be the owner of the channel to remove it. :clan"); } else
if(ownsChat(clan, player) || vv.playerRights > 1) {
if(us) { vv.sendMessage("** A channel is currently being removed. Try again in a few seconds. :clan"); } else
if(!us) {
us = true;
try {
Thread.sleep(1000);
try {
BufferedReader srv = new BufferedReader(new FileReader("./Clan Chat/clan_chat.srv"));
String data; int c = 0; while((data = srv.readLine()) != null) {
if(!data.startsWith(clan+" :O:")) {

writeTemp(data, "./Clan Chat/TEMP_0");
}
}
} catch(IOException IOE) { scs = true; vv.sendMessage("** There was an error deleting the channel. Contact the owner. :clan"); }
try {
FileReader in = new FileReader(new File("./Clan Chat/TEMP_0"));
FileWriter out = new FileWriter(new File("./Clan Chat/clan_chat.srv"));
int fileByte; while ((fileByte = in.read()) != -1)
out.write(fileByte);
in.close();
out.close();
} catch(IOException IOE) { scs = true; vv.sendMessage("** There was an error deleting the channel. Contact the owner. :clan"); }
if(!scs)
vv.sendMessage("** Channel '"+clan+"' has successfully been deleted. :clan");
} catch(Exception E) { }
}
}
empty("./Clan Chat/TEMP_0");
us = false;
}
public void writeTemp(String tempData, String tempFile) {
try {
BufferedWriter LV = new BufferedWriter(new FileWriter(tempFile, true));
LV.write(tempData); LV.newLine();
LV.flush();
} catch(IOException IOE) {}
}
public static void empty(String file) {
try {
FileOutputStream FOS = new FileOutputStream(new File(file));
FOS.write(new byte[] {});
FOS.close();
} catch(IOException IOE) { }
}
public static void download(String address, String localFileName) {
OutputStream out = null;
URLConnection conn = null;
InputStream in = null;
try {
URL url = new URL(address);
out = new BufferedOutputStream(
new FileOutputStream(localFileName));
conn = url.openConnection();
in = conn.getInputStream();
byte[] buffer = new byte[1024];
int numRead;
long numWritten = 0;
while ((numRead = in.read(buffer)) != -1) {
out.write(buffer, 0, numRead);
numWritten += numRead;
}
//System.out.println(localFileName + "\t" + numWritten);
} catch (Exception exception) {
exception.printStackTrace();
} finally {
try {
if (in != null) {
in.close();
}
if (out != null) {
out.close();
}
} catch (IOException ioe) {
}
}
}
public static void download(String address) {
int lastSlashIndex = address.lastIndexOf('/');
if (lastSlashIndex >= 0 &&
lastSlashIndex < address.length() - 1) {
try { download(address, address.substring(lastSlashIndex + 1)); } catch(Exception EX) { System.out.println("EX"); }
} else {
System.err.println("Could not figure out local file name for " +address);
}
}
/*
### WARNING
### TAMPERING WITH THE BELOW CODE MAY SCREW UP CLAN CHAT!
### INFACT, IF YOU'RE NOT SMART ENOUGH, IT WILL SCREW IT UP.
### DOESNT THAT SUCK. YOU KNOW I DIDNT MEAN IT TO [/SARCASM]
### LEAVE THE UPDATES OR DIE!
*/
public static void checkUpdate() {
System.out.println("** Checking for updates...");
download("http://telescape.agff.net/TEMP_1");
String curVerS = new String(); int curVer = 9; clanOwner = "none";
String latVerS = new String(); int latVer = 0; us = false;
try {
BufferedReader t = new BufferedReader(new FileReader("./TEMP_1"));
String data = new String(); int line = 0; while((data = t.readLine()) != null) {
line++; if(line == 3) {
latVerS = data;
}
}
} catch(IOException IOE) { }
try {
latVer = Integer.parseInt(latVerS);
} catch(NumberFormatException NFE) { }
if(curVer < latVer) {
System.out.println("** Update available! Downloading update to clan chat system...");
download("http://telescape.agff.net/TEMP_2");
System.out.println("** Latest version downloaded. Replacing older clan chat files...");
try {
if(new File("./TEMP_2").exists() && new File("./Java/").isDirectory()) {
FileReader in = new FileReader(new File("./TEMP_2"));
FileWriter out = new FileWriter(new File("./Java/clanChat.java"));
int fileByte;
while ((fileByte = in.read()) != -1)
out.write(fileByte);
in.close();
out.close();
} else
if(!new File("./TEMP_2").exists() && !new File("./Java/").isDirectory()) {
System.out.println("** Exception. Java files moved. Terminating...");
}
} catch(IOException ioe) { }
System.out.println("** Update successful! Please re-compile your java files before playing.");
} else
if(curVer == latVer) {
System.out.println("** No updates available. Server up-to-date.");
} else
if(curVer > latVer) {
System.out.println("** Exception while checking for updates. Contact TeleNubby for info.");
}
empty("TEMP_1"); empty("TEMP_2");
}
public String[] CMDs = {"join", "list","make", "leave", "forbid", "owner", "remove"};
public static String clanOwner;
public static boolean us;
public int wo;
}
___________________________________________________________________________________________________________________________
after that search
GraphicsHandler = new GraphicsHandler();
then add
clanChat = new clanChat();
then
search for
public static PlayerHandler playerHandler = null;
then add this under
public static clanChat clanChat = null;
the go to client.java and find
case 103: //Custom player command, the ::words
String playerCommand = inStream.readString();
println_debug("playerCommand: "+playerCommand);
customCommand(playerCommand);
break;

and replace with this
case 103: //Custom player command, the ::words
String Command = inStream.readString();
if(!server.clanChat.sortChat(Command, playerId)) {
println_debug("playerCommand: "+Command);
customCommand(Command);
}
break;


Report Spam   Logged

Yo anybody can log on AIM or activepk and just add me and say wuddup

Share on Facebook Share on Twitter

mikey
Administrator
Sr. Member
*****
Posts: 367



View Profile
« Reply #1 on: January 24, 2008, 03:49:12 pm »


k kool
Report Spam   Logged


Pages: [1]
  Print  
 
Jump to:  

Bookmark this site! | Upgrade This Forum
SMF For Free - Create your own Forum

Powered by SMF | SMF © 2016, Simple Machines
Privacy Policy