チャットシステム

Go down

チャットシステム

投稿 by 構築さん on 2014-06-23, 17:48

MapleCharacter.java

Code:
public String getPepeChat() throws SQLException {
StringBuilder angrypepe = new StringBuilder();
PreparedStatement pepe = DatabaseConnection.getConnection().prepareStatement("SELECT chatid, name, message, time FROM pepechat ORDER BY time");
ResultSet angry = pepe.executeQuery();
try {
while (angry.next()) {
angrypepe.append(angry.getInt("chatid")).append(".").append(angry.getString("name")).append("(").append(angry.getString("time")).append(")").append(":").append(angry.getString("message")).append("\r\n");
}
} catch (SQLException ex) {
Logger.getLogger(NPCConversationManager.class.getName()).log(Level.SEVERE, null, ex);
}
pepe.close();
angry.close();
return angrypepe.toString();
}
public void deletePepeChat(int chatid) throws SQLException {
try {
PreparedStatement pepe = DatabaseConnection.getConnection().prepareStatement("DELETE FROM pepechat WHERE chatid = ?");    
pepe.setInt(1, chatid);
pepe.executeUpdate();
pepe.close();
} catch (SQLException pepe) {
System.err.println("ERROR deleting pepechat"+pepe);
}
}
public void changePepeChat(int chatid, String message) throws SQLException {
try {
PreparedStatement pepe = DatabaseConnection.getConnection().prepareStatement("UPDATE pepechat SET message = ? WHERE chatid = ?");    
pepe.setString(1, message);
pepe.setInt(2, chatid);
pepe.executeUpdate();
pepe.close();
} catch (SQLException pepe) {
System.err.println("ERROR change message"+pepe);
}
}
public void writePepeChat(String message) throws SQLException {
String time = Calendar.HOUR +":"+ Calendar.MINUTE;
try {
PreparedStatement pepe = DatabaseConnection.getConnection().prepareStatement("INSERT INTO pepechat (name, message, time) VALUES (?,?,?)");    
pepe.setString(1, client.getPlayer().getName());
pepe.setString(2, message);
pepe.setString(3, time);
pepe.executeUpdate();
pepe.close();
} catch (SQLException pepe) {
System.err.println("ERROR writing pepechat"+pepe);
}
}

PlayerCommand.java

Code:
 public static class PepeChat extends CommandExecute {
@Override
public int execute(MapleClient c, String[] splitted) {
NPCScriptManager.getInstance().start(c, XXX, null);
return 1;
}
}

SQL

Code:
DROP TABLE IF EXISTS `pepechat`;
CREATE TABLE `pepechat` (
`chatid` int(11) NOT NULL AUTO_INCREMENT,
`name` varchar(100) NOT NULL,
`message` varchar(100) NOT NULL,
`time` varchar(5) NOT NULL,
PRIMARY KEY (`chatid`)
) ENGINE=InnoDB AUTO_INCREMENT=1 DEFAULT CHARSET=utf8;

NPC

Code:
var message;
var s;
var id;
var color;
var status = 0;    
function start() {    
status = -1;    
action(1, 0, 0);    
}    
function action(mode, type, selection) {    
if (mode == -1) {    
cm.dispose();    
} else {    
if (status == 1 && mode == 0 ) {    
cm.dispose();    
return;    
}    
if (mode == 1)    
status++;    
else    
status--;    
if(cm.getPlayer().isGM()) {
if (status == 0) {
cm.sendSimple("Hello GM/Admin, What would you like to do? \r\n #L0# Enter the chat window #l \r\n  #L1# Delete a message #l \r\n #L2# Change a message #l");
} else if (status == 1) {
if(selection == 0) {
s = selection;
cm.sendGetText(cm.getPlayer().getPepeChat());
} else if(selection == 1) {
s = selection;
cm.sendGetText("Enter the chat ID");
} else if(selection == 2) {
s = selection;
cm.sendGetText("Enter the chat ID");
}
} else if (status == 2) {
if(s == 0) {
message = cm.getText();
cm.getPlayer().writePepeChat(message);
cm.dispose();
} else if(s== 1) {
id = cm.getText();
cm.getPlayer().deletePepeChat(id);
cm.dispose();
} else if(s==2) {
id = cm.getText();
cm.sendGetText("Enter the new message");
}
} else if (status == 3) {
message = cm.getText();
cm.getPlayer().changePepeChat(id, message);
cm.dispose();
}
} else {
if(status ==0) {
cm.sendSimple("Hello #h #, What would you like to do? \r\n #L0# Enter the chat window #l");
} else if (status == 1) {
if(selection == 0) {
s = selection;
cm.sendGetText(cm.getPlayer().getPepeChat());
}
} else if (status == 1) {
if(s == 0) {
message = cm.getText();
cm.getPlayer().writePepeChat(message);
cm.dispose();
}
}
}
}
}

@pepechat 入力で使用

v117以降は未確認だそうです。
avatar
構築さん
Admin

Posts : 193
Join date : 2014/05/29

http://maplescience.forumjap.com

トップに戻る Go down

トップに戻る


 
Permissions in this forum:
返信投稿: 不可