|
|
Java-Quelltext |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
/* Banana-Chat - The first Open Source Knuddels Emulator * Copyright (C) 2011 Flav <http://banana-coding.com> * * Diese Datei unterliegt dem Copyright von Banana-Coding und * darf verändert, aber weder in andere Projekte eingefügt noch * reproduziert werden. * * Der Emulator dient - sofern der Client nicht aus Eigenproduktion * stammt - nur zu Lernzwecken, das Hosten des originalen Clients * ist untersagt und wird der Knuddels GmbH gemeldet. */ package knuddels; /** * * @author Flav */ public enum ReceiveOpcode { EXCEPTION("1"), DISCONNECT("d"), CHAT("e"), EDIT("edit"), CMC("cmc"), PING("h"), POLL("iv"), LINK_CLICKED("j"), JOIN_CHANNEL("n"), Q_TOKEN("q"), REQUEST_USER_LIST("r"), HANDSHAKE("t"), REQUEST_HELP("u"), LEAVE_CHANNEL("w"), WHOIS("whois"); private String opcode; private ReceiveOpcode(String opcode) { this.opcode = opcode; } public String getValue() { return opcode; } } |
|
|
Java-Quelltext |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 |
/* Banana-Chat - The first Open Source Knuddels Emulator * Copyright (C) 2011 Flav <http://banana-coding.com> * * Diese Datei unterliegt dem Copyright von Banana-Coding und * darf verändert, aber weder in andere Projekte eingefügt noch * reproduziert werden. * * Der Emulator dient - sofern der Client nicht aus Eigenproduktion * stammt - nur zu Lernzwecken, das Hosten des originalen Clients * ist untersagt und wird der Knuddels GmbH gemeldet. */ package knuddels; import handler.*; import java.io.IOException; import java.io.InputStream; import java.net.Socket; /** * * @author Flav */ public class SessionHandler extends Thread { private Socket socket; public SessionHandler(Socket socket) { this.socket = socket; } @Override public void run() { Client client = new Client(socket); try { InputStream in = socket.getInputStream(); byte type = (byte) in.read(); if (type == 0x00) { while (true) { int first = in.read(); if (first == -1) { break; } int len; byte b = (byte) first; if (b >= 0) { len = b + 1; } else { len = (b & 0x1F) + 1; int count = (b & 0x60) >>> 5; for (int i = 0; i < count; i++) { len += in.read() << (i << 3) + 5; } } byte[] buffer = new byte[len]; for (int i = 0; i < len; i++) { buffer[i] = (byte) in.read(); } String packet = new String(buffer, "UTF8"); String[] tokens = packet.split("\0"); String opcode = tokens[0]; if (opcode.equals(ReceiveOpcode.EXCEPTION.getValue())) { } else if (opcode.equals(ReceiveOpcode.DISCONNECT.getValue())) { } else if (opcode.equals(ReceiveOpcode.CHAT.getValue())) { ChatHandler.handle(tokens, client); } else if (opcode.equals(ReceiveOpcode.PING.getValue())) { PingHandler.handle(tokens, client); } else if (opcode.equals(ReceiveOpcode.POLL.getValue())) { PollHandler.handle(tokens, client); } else if (opcode.equals(ReceiveOpcode.LINK_CLICKED.getValue())) { } else if (opcode.equals(ReceiveOpcode.JOIN_CHANNEL.getValue())) { JoinChannelHandler.handle(tokens, client); } else if (opcode.equals(ReceiveOpcode.Q_TOKEN.getValue())) { } else if (opcode.equals(ReceiveOpcode.REQUEST_USER_LIST.getValue())) { RequestUserListHandler.handle(tokens, client); } else if (opcode.equals(ReceiveOpcode.HANDSHAKE.getValue())) { HandshakeHandler.handle(tokens, client); } else if (opcode.equals(ReceiveOpcode.REQUEST_HELP.getValue())) { RequestHelpHandler.handle(tokens, client); } else if (opcode.equals(ReceiveOpcode.LEAVE_CHANNEL.getValue())) { LeaveChannelHandler.handle(tokens, client); } else if (opcode.equals(ReceiveOpcode.WHOIS.getValue())) { } else if (opcode.equals(ReceiveOpcode.CMC.getValue())) { CmcHandler.handle(tokens, channel, client); <<<< Hier kommt der fehler }else if (opcode.equals(ReceiveOpcode.EDIT.getValue())) { EditHandler.handle(tokens, client); } else { System.out.println(String.format("Unhandled opcode: %s", opcode)); } } } else if (type == 0x02) { // registration } } catch (IOException e) { } finally { client.disconnect(); } } } |
|
|
Java-Quelltext |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package handler; import knuddels.Client; import knuddels.Channel; import tools.popup.Popup; import knuddels.Server; import tools.KCodeParser; /** * * @author Marlies */ public class CmcHandler { public static void handle(String[] tokens, Channel channel, Client client ){ String info = tokens[3].trim(); info = KCodeParser.parse(info, !client.isModerator(), 0, 10, 20); info = Server.get().parseSmileys(info); String errors = ""; if(info.length() > 10000) { errors += String.format("#Deine Angabe unter _'Info'_ ist %s Zeichen _zu lang_.", (info.length()-10000)); } if(!errors.isEmpty()) { client.send(Popup.create("Problem", "Problem", String.format("#Bei der Änderung deiner Daten sind folgende _Probleme_ aufgetreten:#%s", errors), 400, 250)); return; } client.send(Popup.create("Änderungen übernommen", "Änderungen übernommen", "#Alle Änderungen wurden _gespeichert_.", 400, 250)); channel.setInfo(info); } } |
|
|
Java-Quelltext |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
else if (cmd.equals("cmc")){ Popup popup = new Popup("Cmc", "Cmc", "", 0, 0); Panel panel10 = new Panel(); panel10.addComponent(new Label("Info")); panel10.addComponent(new TextField(15, channel.getInfo())); popup.addPanel(panel10); Panel panel11 = new Panel(); Button button = new Button("Speichern"); button.disableClose(); button.enableAction(); panel11.addComponent(button); Button button5 = new Button("Abbrechen"); panel11.addComponent(button5); popup.addPanel(panel11); popup.setOpcode(ReceiveOpcode.CMC.getValue(), "cmc"); client.send(popup.toString()); } |
|
|
Java-Quelltext |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 |
/* Banana-Chat - The first Open Source Knuddels Emulator * Copyright (C) 2011 Flav <http://banana-coding.com> * * Diese Datei unterliegt dem Copyright von Banana-Coding und * darf verändert, aber weder in andere Projekte eingefügt noch * reproduziert werden. * * Der Emulator dient - sofern der Client nicht aus Eigenproduktion * stammt - nur zu Lernzwecken, das Hosten des originalen Clients * ist untersagt und wird der Knuddels GmbH gemeldet. */ package knuddels; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; import java.util.ArrayList; import java.util.List; import java.util.Random; import knuddels.game.Game; import knuddels.game.Mafia; import knuddels.game.WordMix; import tools.KCodeParser; import tools.PacketCreator; import tools.database.ConnectionPool; import tools.database.PoolConnection; /** * * @author Flav */ public class Channel { private final List<Client> clients; private String name; private String info; private short size; private String topic; private Game game; private String backgroundImage; private byte backgroundPosition; private ChannelStyle style; public Channel(ResultSet rs, ChannelStyle style) throws SQLException { clients = new ArrayList<Client>(); name = rs.getString("name"); info = rs.getString("info"); size = rs.getShort("size"); topic = rs.getString("topic"); String gameName = rs.getString("game"); if (gameName == null) { game = null; } else if (gameName.equals("MAFIA")) { game = new Mafia(this); } else if (gameName.equals("WORDMIX")) { game = new WordMix(this); } backgroundImage = rs.getString("backgroundImage"); backgroundPosition = rs.getByte("backgroundPosition"); this.style = style; } public String getName() { return name; } public String getInfo(){ return info; } public short getSize() { return size; } public String getTopic() { return topic; } public void setInfo(String info){ this.info = info; PoolConnection pcon = ConnectionPool.getConnection(); PreparedStatement ps = null; try { Connection con = pcon.connect(); ps = con.prepareStatement("UPDATE `channels` SET `info` = ? WHERE `name` = ?"); ps.setString(1, info); ps.setString(2, name); ps.executeUpdate(); } catch (SQLException e){ e.printStackTrace(); } finally{ if (ps != null){ try{ ps.close(); } catch (SQLException e){ } } } pcon.close(); } public void setTopic(String topic) { this.topic = topic; PoolConnection pcon = ConnectionPool.getConnection(); PreparedStatement ps = null; try { Connection con = pcon.connect(); ps = con.prepareStatement("UPDATE `channels` SET `topic` = ? WHERE `name` = ?"); ps.setString(1, topic); ps.setString(2, name); ps.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { if (ps != null) { try { ps.close(); } catch (SQLException e) { } } pcon.close(); } if (topic != null) { for (Client client : getClients()) { client.sendButlerMessage(name, String.format("°BB°_Dieser Channel hat folgendes Thema:°r°#%s", topic)); } } } public Game getGame() { return game; } public String getBackgroundImage() { return backgroundImage; } public byte getBackgroundPosition() { return backgroundPosition; } public ChannelStyle getStyle() { return style; } public void broadcastMessage(String message, Client client, boolean fromGame) { if (!fromGame && game != null && !game.parsePublicMessage(message, client)) { return; } message = KCodeParser.parse(message, !client.isModerator(), 5, 10, 20); message = Server.get().parseSmileys(message); if (message.isEmpty()) { return; } String msg = PacketCreator.publicMessage(client.getName(), name, message); for (Client c : getClients()) { c.send(msg); } } public void broadcastButlerMessage(String message) { String msg = PacketCreator.publicMessage(Server.get().getButler().getName(), name, message); for (Client c : getClients()) { c.send(msg); } } public void broadcastAction(String sender, String message) { String action = PacketCreator.action(sender, name, message); for (Client c : getClients()) { c.send(action); } } public int countClients() { int count = getClients().size(); if (count > size) { count = size; } return count; } public List<Client> getClients() { synchronized (clients) { return clients; } } public void addClient(Client client) { synchronized (clients) { clients.add(client); } } public void join(Client client) { client.send(PacketCreator.userList(this)); addClient(client); for (Client c : getClients()) { c.send(PacketCreator.addUser(this, client, c == client)); } PoolConnection pconla = ConnectionPool.getConnection(); PreparedStatement psla = null; PreparedStatement pslb = null; PreparedStatement pslc = null; try { Connection conla = pconla.connect(); psla = conla.prepareStatement("SELECT count(name) as summe FROM `vermisst` where vermisst = ?"); psla.setString(1, client.getName()); ResultSet rsla = psla.executeQuery(); Connection conlb = pconla.connect(); pslb = conlb.prepareStatement("SELECT name FROM `vermisst` where vermisst = ? group by name"); pslb.setString(1, client.getName()); ResultSet rslb = pslb.executeQuery(); String vermisst = ""; int lol = 1; String ha = ""; while(rsla.next()) { if(rsla.getInt("summe") >= 3) { while(rslb.next()) { if(lol != 1) { vermisst += ", "; ha = "haben"; } else { ha = "hat"; } vermisst += String.format("_°>_h%s|/serverpp "|/w "<°_", rslb.getString("name")); lol++; } } } if(!vermisst.isEmpty()) { client.sendButlerMessage(name, String.format("°BB°%s %s dich ziemlich arg vermisst...", vermisst, ha)); Connection conlc = pconla.connect(); pslc = conlc.prepareStatement("delete from vermisst where vermisst = ?"); pslc.setString(1, client.getName()); pslc.execute(); } } catch (SQLException e) { e.printStackTrace(); } finally { if (psla != null) { try { psla.close(); } catch (SQLException e) { } } pconla.close(); } if (topic != null) { client.sendButlerMessage(name, String.format("°BB°_Dieser Channel hat folgendes Thema:°r°#%s", topic)); } if (Server.get().getButler().getKnuddels() > 0) { Random random = new Random(); int randomInt = random.nextInt(50); if (randomInt == 25) { broadcastAction(">", String.format("°>_h%s|/serverpp "|/w "<° hat °>_h%s|/serverpp "|/w "<° scheinbar richtig gern und °RR°knuddelt°BB° eifrig drauf los.", Server.get().getButler().getName(), client.getName())); client.setKnuddels(client.getKnuddels() + 1); Server.get().getButler().setKnuddels(Server.get().getButler().getKnuddels() - 1); } } } public void leave(Client client) { synchronized (clients) { clients.remove(client); } String leave = PacketCreator.removeUser(client.getName(), name); for (Client c : getClients()) { c.send(leave); } if (game != null) { game.onLeave(client); } } } |
|
|
Java-Quelltext |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
} else if (cmd.equals("cmc")) { Popup popup = new Popup("Cmc", "Cmc", "", 0, 0); Panel panel10 = new Panel(); panel10.addComponent(new Label("Info")); panel10.addComponent(new TextField(15, channel.getInfo())); popup.addPanel(panel10); Panel panel11 = new Panel(); Button button = new Button("Speichern"); button.disableClose(); button.enableAction(); panel11.addComponent(button); Button button5 = new Button("Abbrechen"); panel11.addComponent(button5); popup.addPanel(panel11); popup.setOpcode(ReceiveOpcode.CMC.getValue(), "cmc"); client.send(popup.toString()); } |
|
|
Java-Quelltext |
1 2 |
public class SessionHandler extends Thread { private Socket socket; |
|
|
Java-Quelltext |
1 2 3 |
public class SessionHandler extends Thread { private Socket socket; private Channel channel; |
|
|
Java-Quelltext |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package handler; import knuddels.Client; import knuddels.Channel; import tools.popup.Popup; import knuddels.Server; import tools.KCodeParser; /** * * @author Marlies */ public class CmcHandler { public static void handle(String[] tokens, Channel channel, Client client ){ String info = tokens[3].trim(); info = KCodeParser.parse(info, !client.isModerator(), 0, 10, 20); info = Server.get().parseSmileys(info); String errors = ""; if(info.length() > 10000) { errors += String.format("#Deine Angabe unter _'Info'_ ist %s Zeichen _zu lang_.", (info.length()-1000)); } if(!errors.isEmpty()) { client.send(Popup.create("Problem", "Problem", String.format("#Bei der Änderung deiner Daten sind folgende _Probleme_ aufgetreten:#%s", errors), 400, 250)); return; } client.send(Popup.create("Änderungen übernommen", "Änderungen übernommen", "#Alle Änderungen wurden _gespeichert_.", 400, 250)); channel.setInfo(info); } } |
Dieser Beitrag wurde bereits 2 mal editiert, zuletzt von »masterx« (9. Februar 2012, 11:59)
Benutzer, die sich für diesen Beitrag bedankt haben:
Kommt immer noch /cmc exestiert leider nicht
|
|
Java-Quelltext |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
} else if (cmd.equals("cmc")){ Popup popup = new Popup("Cmc", "Cmc", "", 0, 0); Panel panel10 = new Panel(); panel10.addComponent(new Label("Info")); panel10.addComponent(new TextField(15, channel.getInfo())); popup.addPanel(panel10); Panel panel13 = new Panel(); Button button = new Button("Speichern"); button.disableClose(); button.enableAction(); panel13.addComponent(button); Button button5 = new Button("Abbrechen"); panel13.addComponent(button5); popup.addPanel(panel13); popup.setOpcode(ReceiveOpcode.CMC.getValue(), "Cmc"); client.send(popup.toString()); |
Kommt immer noch /cmc exestiert leider nicht
Das Ersetzen mit deinem Jetzigen:
![]()
Java-Quelltext
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 } else if (cmd.equals("cmc")){ Popup popup = new Popup("Cmc", "Cmc", "", 0, 0); Panel panel10 = new Panel(); panel10.addComponent(new Label("Info")); panel10.addComponent(new TextField(15, channel.getInfo())); popup.addPanel(panel10); Panel panel13 = new Panel(); Button button = new Button("Speichern"); button.disableClose(); button.enableAction(); panel13.addComponent(button); Button button5 = new Button("Abbrechen"); panel13.addComponent(button5); popup.addPanel(panel13); popup.setOpcode(ReceiveOpcode.CMC.getValue(), "Cmc"); client.send(popup.toString());
Kommt immer noch /cmc exestiert leider nicht
Das Ersetzen mit deinem Jetzigen:
![]()
Java-Quelltext
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 } else if (cmd.equals("cmc")){ Popup popup = new Popup("Cmc", "Cmc", "", 0, 0); Panel panel10 = new Panel(); panel10.addComponent(new Label("Info")); panel10.addComponent(new TextField(15, channel.getInfo())); popup.addPanel(panel10); Panel panel13 = new Panel(); Button button = new Button("Speichern"); button.disableClose(); button.enableAction(); panel13.addComponent(button); Button button5 = new Button("Abbrechen"); panel13.addComponent(button5); popup.addPanel(panel13); popup.setOpcode(ReceiveOpcode.CMC.getValue(), "Cmc"); client.send(popup.toString());
Zitat von »Kosi«
Kommt immer noch /cmc exestiert leider nicht
Das Ersetzen mit deinem Jetzigen:
Java-Quelltext
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
Sorry hat alles geklappt, ich war nur zu doof die bananachat.jar zu verschieben.} else if (cmd.equals("cmc")){
Popup popup = new Popup("Cmc", "Cmc", "", 0, 0);
Panel panel10 = new Panel();
panel10.addComponent(new Label("Info"));
panel10.addComponent(new TextField(15, channel.getInfo()));
popup.addPanel(panel10);
Panel panel13 = new Panel();
Button button = new Button("Speichern");
button.disableClose();
button.enableAction();
panel13.addComponent(button);
Button button5 = new Button("Abbrechen");
panel13.addComponent(button5);
popup.addPanel(panel13);
popup.setOpcode(ReceiveOpcode.CMC.getValue(), "Cmc");
client.send(popup.toString());
|
|
Java-Quelltext |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
PoolConnection pcon = ConnectionPool.getConnection();
PreparedStatement ps = null;
try {
Connection con = pcon.connect();
ps = con.prepareStatement("update channels set info = ? where name = ?");ps.setString(1, info);ps.setString(2, name);
ps.executeUpdate();
} catch (SQLException e) {
e.printStackTrace();
} finally {
if (ps != null) {
try {
ps.close();
} catch (SQLException e) {
}
}
pcon.close();
}
|
|
|
Java-Quelltext |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
public String setInfo(){ return info; } public void setInfo(String info) { PoolConnection pcon = ConnectionPool.getConnection(); PreparedStatement ps = null; try { Connection con = pcon.connect(); ps = con.prepareStatement("UPDATE `channels` SET `info` = ? WHERE `name` = ?"); ps.setString(1, info); ps.setString(2, name); ps.executeUpdate(); } catch (SQLException e) { e.printStackTrace(); } finally { if (ps != null) { try { ps.close(); } catch (SQLException e) { } } pcon.close(); } } |
|
|
Java-Quelltext |
1 2 3 |
else if (opcode.equals(ReceiveOpcode.CMC.getValue())) { CmcHandler.handle(tokens, channel, client); } |
|
|
Java-Quelltext |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
/* * To change this template, choose Tools | Templates * and open the template in the editor. */ package handler; import knuddels.Channel; import knuddels.Client; import knuddels.Server; import tools.KCodeParser; import tools.popup.Popup; /** * * @author Marlies */ public class CmcHandler { public static void handle(String[] tokens, Channel channel, Client client ){ String info = tokens[3].trim(); info = KCodeParser.parse(info, !client.isModerator(), 0, 10, 20); info = Server.get().parseSmileys(info); String errors = ""; if(info.length() > 10000) { errors += String.format("#Deine Angabe unter _'Info'_ ist %s Zeichen _zu lang_.", (info.length()-1000)); } if(!errors.isEmpty()) { client.send(Popup.create("Problem", "Problem", String.format("#Bei der Änderung deiner Daten sind folgende _Probleme_ aufgetreten:#%s", errors), 400, 250)); return; } client.send(Popup.create("Änderungen übernommen", "Änderungen übernommen", "#Alle Änderungen wurden _gespeichert_.", 400, 250)); channel.setInfo(info); } } } } |
Dieser Beitrag wurde bereits 1 mal editiert, zuletzt von »Kosi« (11. Februar 2012, 19:22)