Project update.
This commit is contained in:
245
trunk/java/com/l2jmobius/gameserver/communitybbs/BB/Forum.java
Normal file
245
trunk/java/com/l2jmobius/gameserver/communitybbs/BB/Forum.java
Normal file
@ -0,0 +1,245 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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.l2jmobius.gameserver.communitybbs.BB;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.commons.database.pool.impl.ConnectionFactory;
|
||||
import com.l2jmobius.gameserver.communitybbs.Manager.ForumsBBSManager;
|
||||
import com.l2jmobius.gameserver.communitybbs.Manager.TopicBBSManager;
|
||||
|
||||
public final class Forum
|
||||
{
|
||||
private static final Logger _log = Logger.getLogger(Forum.class.getName());
|
||||
|
||||
// type
|
||||
public static final int ROOT = 0;
|
||||
public static final int NORMAL = 1;
|
||||
public static final int CLAN = 2;
|
||||
public static final int MEMO = 3;
|
||||
public static final int MAIL = 4;
|
||||
// perm
|
||||
public static final int INVISIBLE = 0;
|
||||
public static final int ALL = 1;
|
||||
public static final int CLANMEMBERONLY = 2;
|
||||
public static final int OWNERONLY = 3;
|
||||
|
||||
private final List<Forum> _children = new ArrayList<>();
|
||||
private final Map<Integer, Topic> _topic = new ConcurrentHashMap<>();
|
||||
private final int _forumId;
|
||||
private String _forumName;
|
||||
private int _forumType;
|
||||
private int _forumPost;
|
||||
private int _forumPerm;
|
||||
private final Forum _fParent;
|
||||
private int _ownerID;
|
||||
private boolean _loaded = false;
|
||||
|
||||
/**
|
||||
* Creates new instance of Forum. When you create new forum, use {@link com.l2jmobius.gameserver.communitybbs.Manager.ForumsBBSManager# addForum(com.l2jmobius.gameserver.communitybbs.BB.Forum)} to add forum to the forums manager.
|
||||
* @param Forumid
|
||||
* @param FParent
|
||||
*/
|
||||
public Forum(int Forumid, Forum FParent)
|
||||
{
|
||||
_forumId = Forumid;
|
||||
_fParent = FParent;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name
|
||||
* @param parent
|
||||
* @param type
|
||||
* @param perm
|
||||
* @param OwnerID
|
||||
*/
|
||||
public Forum(String name, Forum parent, int type, int perm, int OwnerID)
|
||||
{
|
||||
_forumName = name;
|
||||
_forumId = ForumsBBSManager.getInstance().getANewID();
|
||||
_forumType = type;
|
||||
_forumPost = 0;
|
||||
_forumPerm = perm;
|
||||
_fParent = parent;
|
||||
_ownerID = OwnerID;
|
||||
parent._children.add(this);
|
||||
ForumsBBSManager.getInstance().addForum(this);
|
||||
_loaded = true;
|
||||
}
|
||||
|
||||
private void load()
|
||||
{
|
||||
try (Connection con = ConnectionFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM forums WHERE forum_id=?"))
|
||||
{
|
||||
ps.setInt(1, _forumId);
|
||||
try (ResultSet rs = ps.executeQuery())
|
||||
{
|
||||
if (rs.next())
|
||||
{
|
||||
_forumName = rs.getString("forum_name");
|
||||
_forumPost = rs.getInt("forum_post");
|
||||
_forumType = rs.getInt("forum_type");
|
||||
_forumPerm = rs.getInt("forum_perm");
|
||||
_ownerID = rs.getInt("forum_owner_id");
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "Data error on Forum " + _forumId + " : " + e.getMessage(), e);
|
||||
}
|
||||
|
||||
try (Connection con = ConnectionFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM topic WHERE topic_forum_id=? ORDER BY topic_id DESC"))
|
||||
{
|
||||
ps.setInt(1, _forumId);
|
||||
try (ResultSet rs = ps.executeQuery())
|
||||
{
|
||||
while (rs.next())
|
||||
{
|
||||
final Topic t = new Topic(Topic.ConstructorType.RESTORE, rs.getInt("topic_id"), rs.getInt("topic_forum_id"), rs.getString("topic_name"), rs.getLong("topic_date"), rs.getString("topic_ownername"), rs.getInt("topic_ownerid"), rs.getInt("topic_type"), rs.getInt("topic_reply"));
|
||||
_topic.put(t.getID(), t);
|
||||
if (t.getID() > TopicBBSManager.getInstance().getMaxID(this))
|
||||
{
|
||||
TopicBBSManager.getInstance().setMaxID(t.getID(), this);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "Data error on Forum " + _forumId + " : " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
private void getChildren()
|
||||
{
|
||||
try (Connection con = ConnectionFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT forum_id FROM forums WHERE forum_parent=?"))
|
||||
{
|
||||
ps.setInt(1, _forumId);
|
||||
try (ResultSet rs = ps.executeQuery())
|
||||
{
|
||||
while (rs.next())
|
||||
{
|
||||
final Forum f = new Forum(rs.getInt("forum_id"), this);
|
||||
_children.add(f);
|
||||
ForumsBBSManager.getInstance().addForum(f);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "Data error on Forum (children): " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public int getTopicSize()
|
||||
{
|
||||
vload();
|
||||
return _topic.size();
|
||||
}
|
||||
|
||||
public Topic getTopic(int j)
|
||||
{
|
||||
vload();
|
||||
return _topic.get(j);
|
||||
}
|
||||
|
||||
public void addTopic(Topic t)
|
||||
{
|
||||
vload();
|
||||
_topic.put(t.getID(), t);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the forum Id
|
||||
*/
|
||||
public int getID()
|
||||
{
|
||||
return _forumId;
|
||||
}
|
||||
|
||||
public String getName()
|
||||
{
|
||||
vload();
|
||||
return _forumName;
|
||||
}
|
||||
|
||||
public int getType()
|
||||
{
|
||||
vload();
|
||||
return _forumType;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param name the forum name
|
||||
* @return the forum for the given name
|
||||
*/
|
||||
public Forum getChildByName(String name)
|
||||
{
|
||||
vload();
|
||||
return _children.stream().filter(f -> f.getName().equals(name)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param id
|
||||
*/
|
||||
public void rmTopicByID(int id)
|
||||
{
|
||||
_topic.remove(id);
|
||||
}
|
||||
|
||||
public void insertIntoDb()
|
||||
{
|
||||
try (Connection con = ConnectionFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("INSERT INTO forums (forum_id,forum_name,forum_parent,forum_post,forum_type,forum_perm,forum_owner_id) VALUES (?,?,?,?,?,?,?)"))
|
||||
{
|
||||
ps.setInt(1, _forumId);
|
||||
ps.setString(2, _forumName);
|
||||
ps.setInt(3, _fParent.getID());
|
||||
ps.setInt(4, _forumPost);
|
||||
ps.setInt(5, _forumType);
|
||||
ps.setInt(6, _forumPerm);
|
||||
ps.setInt(7, _ownerID);
|
||||
ps.execute();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "Error while saving new Forum to db " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public void vload()
|
||||
{
|
||||
if (!_loaded)
|
||||
{
|
||||
load();
|
||||
getChildren();
|
||||
_loaded = true;
|
||||
}
|
||||
}
|
||||
}
|
170
trunk/java/com/l2jmobius/gameserver/communitybbs/BB/Post.java
Normal file
170
trunk/java/com/l2jmobius/gameserver/communitybbs/BB/Post.java
Normal file
@ -0,0 +1,170 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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.l2jmobius.gameserver.communitybbs.BB;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.sql.ResultSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.commons.database.pool.impl.ConnectionFactory;
|
||||
import com.l2jmobius.gameserver.communitybbs.Manager.PostBBSManager;
|
||||
|
||||
/**
|
||||
* @author Maktakien
|
||||
*/
|
||||
public class Post
|
||||
{
|
||||
private static final Logger _log = Logger.getLogger(Post.class.getName());
|
||||
|
||||
public static class CPost
|
||||
{
|
||||
public int postId;
|
||||
public String postOwner;
|
||||
public int postOwnerId;
|
||||
public long postDate;
|
||||
public int postTopicId;
|
||||
public int postForumId;
|
||||
public String postTxt;
|
||||
}
|
||||
|
||||
private final List<CPost> _post = new ArrayList<>();
|
||||
|
||||
/**
|
||||
* @param _PostOwner
|
||||
* @param _PostOwnerID
|
||||
* @param date
|
||||
* @param tid
|
||||
* @param _PostForumID
|
||||
* @param txt
|
||||
*/
|
||||
public Post(String _PostOwner, int _PostOwnerID, long date, int tid, int _PostForumID, String txt)
|
||||
{
|
||||
final CPost cp = new CPost();
|
||||
cp.postId = 0;
|
||||
cp.postOwner = _PostOwner;
|
||||
cp.postOwnerId = _PostOwnerID;
|
||||
cp.postDate = date;
|
||||
cp.postTopicId = tid;
|
||||
cp.postForumId = _PostForumID;
|
||||
cp.postTxt = txt;
|
||||
_post.add(cp);
|
||||
insertindb(cp);
|
||||
}
|
||||
|
||||
public Post(Topic t)
|
||||
{
|
||||
load(t);
|
||||
}
|
||||
|
||||
public void insertindb(CPost cp)
|
||||
{
|
||||
try (Connection con = ConnectionFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("INSERT INTO posts (post_id,post_owner_name,post_ownerid,post_date,post_topic_id,post_forum_id,post_txt) values (?,?,?,?,?,?,?)"))
|
||||
{
|
||||
ps.setInt(1, cp.postId);
|
||||
ps.setString(2, cp.postOwner);
|
||||
ps.setInt(3, cp.postOwnerId);
|
||||
ps.setLong(4, cp.postDate);
|
||||
ps.setInt(5, cp.postTopicId);
|
||||
ps.setInt(6, cp.postForumId);
|
||||
ps.setString(7, cp.postTxt);
|
||||
ps.execute();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "Error while saving new Post to db " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public CPost getCPost(int id)
|
||||
{
|
||||
return _post.get(id);
|
||||
}
|
||||
|
||||
public void deleteme(Topic t)
|
||||
{
|
||||
PostBBSManager.getInstance().delPostByTopic(t);
|
||||
try (Connection con = ConnectionFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("DELETE FROM posts WHERE post_forum_id=? AND post_topic_id=?"))
|
||||
{
|
||||
ps.setInt(1, t.getForumID());
|
||||
ps.setInt(2, t.getID());
|
||||
ps.execute();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "Error while deleting post: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param t
|
||||
*/
|
||||
private void load(Topic t)
|
||||
{
|
||||
try (Connection con = ConnectionFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("SELECT * FROM posts WHERE post_forum_id=? AND post_topic_id=? ORDER BY post_id ASC"))
|
||||
{
|
||||
ps.setInt(1, t.getForumID());
|
||||
ps.setInt(2, t.getID());
|
||||
try (ResultSet rs = ps.executeQuery())
|
||||
{
|
||||
while (rs.next())
|
||||
{
|
||||
final CPost cp = new CPost();
|
||||
cp.postId = rs.getInt("post_id");
|
||||
cp.postOwner = rs.getString("post_owner_name");
|
||||
cp.postOwnerId = rs.getInt("post_ownerid");
|
||||
cp.postDate = rs.getLong("post_date");
|
||||
cp.postTopicId = rs.getInt("post_topic_id");
|
||||
cp.postForumId = rs.getInt("post_forum_id");
|
||||
cp.postTxt = rs.getString("post_txt");
|
||||
_post.add(cp);
|
||||
}
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "Data error on Post " + t.getForumID() + "/" + t.getID() + " : " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param i
|
||||
*/
|
||||
public void updatetxt(int i)
|
||||
{
|
||||
final CPost cp = getCPost(i);
|
||||
try (Connection con = ConnectionFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("UPDATE posts SET post_txt=? WHERE post_id=? AND post_topic_id=? AND post_forum_id=?"))
|
||||
{
|
||||
ps.setString(1, cp.postTxt);
|
||||
ps.setInt(2, cp.postId);
|
||||
ps.setInt(3, cp.postTopicId);
|
||||
ps.setInt(4, cp.postForumId);
|
||||
ps.execute();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "Error while saving new Post to db " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
}
|
152
trunk/java/com/l2jmobius/gameserver/communitybbs/BB/Topic.java
Normal file
152
trunk/java/com/l2jmobius/gameserver/communitybbs/BB/Topic.java
Normal file
@ -0,0 +1,152 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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.l2jmobius.gameserver.communitybbs.BB;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.PreparedStatement;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.commons.database.pool.impl.ConnectionFactory;
|
||||
import com.l2jmobius.gameserver.communitybbs.Manager.TopicBBSManager;
|
||||
|
||||
public class Topic
|
||||
{
|
||||
private static final Logger _log = Logger.getLogger(Topic.class.getName());
|
||||
|
||||
public static final int MORMAL = 0;
|
||||
public static final int MEMO = 1;
|
||||
|
||||
private final int _id;
|
||||
private final int _forumId;
|
||||
private final String _topicName;
|
||||
private final long _date;
|
||||
private final String _ownerName;
|
||||
private final int _ownerId;
|
||||
private final int _type;
|
||||
private final int _cReply;
|
||||
|
||||
/**
|
||||
* @param ct
|
||||
* @param id
|
||||
* @param fid
|
||||
* @param name
|
||||
* @param date
|
||||
* @param oname
|
||||
* @param oid
|
||||
* @param type
|
||||
* @param Creply
|
||||
*/
|
||||
public Topic(ConstructorType ct, int id, int fid, String name, long date, String oname, int oid, int type, int Creply)
|
||||
{
|
||||
_id = id;
|
||||
_forumId = fid;
|
||||
_topicName = name;
|
||||
_date = date;
|
||||
_ownerName = oname;
|
||||
_ownerId = oid;
|
||||
_type = type;
|
||||
_cReply = Creply;
|
||||
TopicBBSManager.getInstance().addTopic(this);
|
||||
|
||||
if (ct == ConstructorType.CREATE)
|
||||
{
|
||||
insertindb();
|
||||
}
|
||||
}
|
||||
|
||||
public void insertindb()
|
||||
{
|
||||
try (Connection con = ConnectionFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("INSERT INTO topic (topic_id,topic_forum_id,topic_name,topic_date,topic_ownername,topic_ownerid,topic_type,topic_reply) values (?,?,?,?,?,?,?,?)"))
|
||||
{
|
||||
ps.setInt(1, _id);
|
||||
ps.setInt(2, _forumId);
|
||||
ps.setString(3, _topicName);
|
||||
ps.setLong(4, _date);
|
||||
ps.setString(5, _ownerName);
|
||||
ps.setInt(6, _ownerId);
|
||||
ps.setInt(7, _type);
|
||||
ps.setInt(8, _cReply);
|
||||
ps.execute();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "Error while saving new Topic to db " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
public enum ConstructorType
|
||||
{
|
||||
RESTORE,
|
||||
CREATE
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the topic Id
|
||||
*/
|
||||
public int getID()
|
||||
{
|
||||
return _id;
|
||||
}
|
||||
|
||||
public int getForumID()
|
||||
{
|
||||
return _forumId;
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the topic name
|
||||
*/
|
||||
public String getName()
|
||||
{
|
||||
return _topicName;
|
||||
}
|
||||
|
||||
public String getOwnerName()
|
||||
{
|
||||
return _ownerName;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param f
|
||||
*/
|
||||
public void deleteme(Forum f)
|
||||
{
|
||||
TopicBBSManager.getInstance().delTopic(this);
|
||||
f.rmTopicByID(getID());
|
||||
try (Connection con = ConnectionFactory.getInstance().getConnection();
|
||||
PreparedStatement ps = con.prepareStatement("DELETE FROM topic WHERE topic_id=? AND topic_forum_id=?"))
|
||||
{
|
||||
ps.setInt(1, getID());
|
||||
ps.setInt(2, f.getID());
|
||||
ps.execute();
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "Error while deleting topic: " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @return the topic date
|
||||
*/
|
||||
public long getDate()
|
||||
{
|
||||
return _date;
|
||||
}
|
||||
}
|
@ -0,0 +1,79 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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.l2jmobius.gameserver.communitybbs.Manager;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.gameserver.network.serverpackets.ShowBoard;
|
||||
|
||||
public abstract class BaseBBSManager
|
||||
{
|
||||
public abstract void parsecmd(String command, L2PcInstance activeChar);
|
||||
|
||||
public abstract void parsewrite(String ar1, String ar2, String ar3, String ar4, String ar5, L2PcInstance activeChar);
|
||||
|
||||
/**
|
||||
* @param html
|
||||
* @param acha
|
||||
*/
|
||||
protected void send1001(String html, L2PcInstance acha)
|
||||
{
|
||||
if (html.length() < 8192)
|
||||
{
|
||||
acha.sendPacket(new ShowBoard(html, "1001"));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param acha
|
||||
*/
|
||||
protected void send1002(L2PcInstance acha)
|
||||
{
|
||||
send1002(acha, " ", " ", "0");
|
||||
}
|
||||
|
||||
/**
|
||||
* @param activeChar
|
||||
* @param string
|
||||
* @param string2
|
||||
* @param string3
|
||||
*/
|
||||
protected void send1002(L2PcInstance activeChar, String string, String string2, String string3)
|
||||
{
|
||||
final List<String> _arg = new ArrayList<>();
|
||||
_arg.add("0");
|
||||
_arg.add("0");
|
||||
_arg.add("0");
|
||||
_arg.add("0");
|
||||
_arg.add("0");
|
||||
_arg.add("0");
|
||||
_arg.add(activeChar.getName());
|
||||
_arg.add(Integer.toString(activeChar.getObjectId()));
|
||||
_arg.add(activeChar.getAccountName());
|
||||
_arg.add("9");
|
||||
_arg.add(string2); // subject?
|
||||
_arg.add(string2); // subject?
|
||||
_arg.add(string); // text
|
||||
_arg.add(string3); // date?
|
||||
_arg.add(string3); // date?
|
||||
_arg.add("0");
|
||||
_arg.add("0");
|
||||
activeChar.sendPacket(new ShowBoard(_arg));
|
||||
}
|
||||
}
|
@ -0,0 +1,155 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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.l2jmobius.gameserver.communitybbs.Manager;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.ResultSet;
|
||||
import java.sql.Statement;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
import java.util.logging.Level;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import com.l2jmobius.commons.database.pool.impl.ConnectionFactory;
|
||||
import com.l2jmobius.gameserver.communitybbs.BB.Forum;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
|
||||
public class ForumsBBSManager extends BaseBBSManager
|
||||
{
|
||||
private static Logger _log = Logger.getLogger(ForumsBBSManager.class.getName());
|
||||
private final List<Forum> _table = new CopyOnWriteArrayList<>();
|
||||
private int _lastid = 1;
|
||||
|
||||
/**
|
||||
* Instantiates a new forums bbs manager.
|
||||
*/
|
||||
protected ForumsBBSManager()
|
||||
{
|
||||
try (Connection con = ConnectionFactory.getInstance().getConnection();
|
||||
Statement s = con.createStatement();
|
||||
ResultSet rs = s.executeQuery("SELECT forum_id FROM forums WHERE forum_type = 0"))
|
||||
{
|
||||
while (rs.next())
|
||||
{
|
||||
final int forumId = rs.getInt("forum_id");
|
||||
final Forum f = new Forum(forumId, null);
|
||||
addForum(f);
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
_log.log(Level.WARNING, "Data error on Forum (root): " + e.getMessage(), e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Inits the root.
|
||||
*/
|
||||
public void initRoot()
|
||||
{
|
||||
_table.forEach(f -> f.vload());
|
||||
_log.info("Loaded " + _table.size() + " forums. Last forum id used: " + _lastid);
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds the forum.
|
||||
* @param ff the forum
|
||||
*/
|
||||
public void addForum(Forum ff)
|
||||
{
|
||||
if (ff == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
_table.add(ff);
|
||||
|
||||
if (ff.getID() > _lastid)
|
||||
{
|
||||
_lastid = ff.getID();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parsecmd(String command, L2PcInstance activeChar)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the forum by name.
|
||||
* @param name the forum name
|
||||
* @return the forum by name
|
||||
*/
|
||||
public Forum getForumByName(String name)
|
||||
{
|
||||
return _table.stream().filter(f -> f.getName().equals(name)).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates the new forum.
|
||||
* @param name the forum name
|
||||
* @param parent the parent forum
|
||||
* @param type the forum type
|
||||
* @param perm the perm
|
||||
* @param oid the oid
|
||||
* @return the new forum
|
||||
*/
|
||||
public Forum createNewForum(String name, Forum parent, int type, int perm, int oid)
|
||||
{
|
||||
final Forum forum = new Forum(name, parent, type, perm, oid);
|
||||
forum.insertIntoDb();
|
||||
return forum;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the a new Id.
|
||||
* @return the a new Id
|
||||
*/
|
||||
public int getANewID()
|
||||
{
|
||||
return ++_lastid;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the forum by Id.
|
||||
* @param idf the the forum Id
|
||||
* @return the forum by Id
|
||||
*/
|
||||
public Forum getForumByID(int idf)
|
||||
{
|
||||
return _table.stream().filter(f -> f.getID() == idf).findFirst().orElse(null);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parsewrite(String ar1, String ar2, String ar3, String ar4, String ar5, L2PcInstance activeChar)
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the single instance of ForumsBBSManager.
|
||||
* @return single instance of ForumsBBSManager
|
||||
*/
|
||||
public static ForumsBBSManager getInstance()
|
||||
{
|
||||
return SingletonHolder._instance;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final ForumsBBSManager _instance = new ForumsBBSManager();
|
||||
}
|
||||
}
|
@ -0,0 +1,211 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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.l2jmobius.gameserver.communitybbs.Manager;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import com.l2jmobius.gameserver.communitybbs.BB.Forum;
|
||||
import com.l2jmobius.gameserver.communitybbs.BB.Post;
|
||||
import com.l2jmobius.gameserver.communitybbs.BB.Post.CPost;
|
||||
import com.l2jmobius.gameserver.communitybbs.BB.Topic;
|
||||
import com.l2jmobius.gameserver.handler.CommunityBoardHandler;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.util.StringUtil;
|
||||
|
||||
public class PostBBSManager extends BaseBBSManager
|
||||
{
|
||||
private final Map<Topic, Post> _postByTopic = new ConcurrentHashMap<>();
|
||||
|
||||
public Post getGPosttByTopic(Topic t)
|
||||
{
|
||||
Post post = _postByTopic.get(t);
|
||||
if (post == null)
|
||||
{
|
||||
post = new Post(t);
|
||||
_postByTopic.put(t, post);
|
||||
}
|
||||
return post;
|
||||
}
|
||||
|
||||
public void delPostByTopic(Topic t)
|
||||
{
|
||||
_postByTopic.remove(t);
|
||||
}
|
||||
|
||||
public void addPostByTopic(Post p, Topic t)
|
||||
{
|
||||
if (_postByTopic.get(t) == null)
|
||||
{
|
||||
_postByTopic.put(t, p);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parsecmd(String command, L2PcInstance activeChar)
|
||||
{
|
||||
if (command.startsWith("_bbsposts;read;"))
|
||||
{
|
||||
final StringTokenizer st = new StringTokenizer(command, ";");
|
||||
st.nextToken();
|
||||
st.nextToken();
|
||||
final int idf = Integer.parseInt(st.nextToken());
|
||||
final int idp = Integer.parseInt(st.nextToken());
|
||||
String index = null;
|
||||
if (st.hasMoreTokens())
|
||||
{
|
||||
index = st.nextToken();
|
||||
}
|
||||
int ind = 0;
|
||||
if (index == null)
|
||||
{
|
||||
ind = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ind = Integer.parseInt(index);
|
||||
}
|
||||
|
||||
showPost((TopicBBSManager.getInstance().getTopicByID(idp)), ForumsBBSManager.getInstance().getForumByID(idf), activeChar, ind);
|
||||
}
|
||||
else if (command.startsWith("_bbsposts;edit;"))
|
||||
{
|
||||
final StringTokenizer st = new StringTokenizer(command, ";");
|
||||
st.nextToken();
|
||||
st.nextToken();
|
||||
final int idf = Integer.parseInt(st.nextToken());
|
||||
final int idt = Integer.parseInt(st.nextToken());
|
||||
final int idp = Integer.parseInt(st.nextToken());
|
||||
showEditPost((TopicBBSManager.getInstance().getTopicByID(idt)), ForumsBBSManager.getInstance().getForumByID(idf), activeChar, idp);
|
||||
}
|
||||
else
|
||||
{
|
||||
CommunityBoardHandler.separateAndSend("<html><body><br><br><center>the command: " + command + " is not implemented yet</center><br><br></body></html>", activeChar);
|
||||
}
|
||||
}
|
||||
|
||||
private void showEditPost(Topic topic, Forum forum, L2PcInstance activeChar, int idp)
|
||||
{
|
||||
if (topic == null)
|
||||
{
|
||||
CommunityBoardHandler.separateAndSend("<html><body><br><br><center>Error: This topic does not exist!</center></body></html>", activeChar);
|
||||
}
|
||||
else
|
||||
{
|
||||
final Post p = getGPosttByTopic(topic);
|
||||
if ((forum == null) || (p == null))
|
||||
{
|
||||
CommunityBoardHandler.separateAndSend("<html><body><br><br><center>Error: This forum or post does not exist!</center></body></html>", activeChar);
|
||||
}
|
||||
else
|
||||
{
|
||||
showHtmlEditPost(topic, activeChar, forum, p);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void showPost(Topic topic, Forum forum, L2PcInstance activeChar, int ind)
|
||||
{
|
||||
if ((forum == null) || (topic == null))
|
||||
{
|
||||
CommunityBoardHandler.separateAndSend("<html><body><br><br><center>Error: This forum is not implemented yet!</center></body></html>", activeChar);
|
||||
}
|
||||
else if (forum.getType() == Forum.MEMO)
|
||||
{
|
||||
showMemoPost(topic, activeChar, forum);
|
||||
}
|
||||
else
|
||||
{
|
||||
CommunityBoardHandler.separateAndSend("<html><body><br><br><center>The forum: " + forum.getName() + " is not implemented yet!</center></body></html>", activeChar);
|
||||
}
|
||||
}
|
||||
|
||||
private void showHtmlEditPost(Topic topic, L2PcInstance activeChar, Forum forum, Post p)
|
||||
{
|
||||
final String html = StringUtil.concat("<html><body><br><br><table border=0 width=610><tr><td width=10></td><td width=600 align=left><a action=\"bypass _bbshome\">HOME</a> > <a action=\"bypass _bbsmemo\">", forum.getName(), " Form</a></td></tr></table><img src=\"L2UI.squareblank\" width=\"1\" height=\"10\"><center><table border=0 cellspacing=0 cellpadding=0><tr><td width=610><img src=\"sek.cbui355\" width=\"610\" height=\"1\"><br1><img src=\"sek.cbui355\" width=\"610\" height=\"1\"></td></tr></table><table fixwidth=610 border=0 cellspacing=0 cellpadding=0><tr><td><img src=\"l2ui.mini_logo\" width=5 height=20></td></tr><tr><td><img src=\"l2ui.mini_logo\" width=5 height=1></td><td align=center FIXWIDTH=60 height=29>&$413;</td><td FIXWIDTH=540>", topic.getName(), "</td><td><img src=\"l2ui.mini_logo\" width=5 height=1></td></tr></table><table fixwidth=610 border=0 cellspacing=0 cellpadding=0><tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr><tr><td><img src=\"l2ui.mini_logo\" width=5 height=1></td><td align=center FIXWIDTH=60 height=29 valign=top>&$427;</td><td align=center FIXWIDTH=540><MultiEdit var =\"Content\" width=535 height=313></td><td><img src=\"l2ui.mini_logo\" width=5 height=1></td></tr><tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr></table><table fixwidth=610 border=0 cellspacing=0 cellpadding=0><tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr><tr><td><img src=\"l2ui.mini_logo\" width=5 height=1></td><td align=center FIXWIDTH=60 height=29> </td><td align=center FIXWIDTH=70><button value=\"&$140;\" action=\"Write Post ", String.valueOf(forum.getID()), ";", String.valueOf(topic.getID()), ";0 _ Content Content Content\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td><td align=center FIXWIDTH=70><button value = \"&$141;\" action=\"bypass _bbsmemo\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\"> </td><td align=center FIXWIDTH=400> </td><td><img src=\"l2ui.mini_logo\" width=5 height=1></td></tr></table></center></body></html>");
|
||||
send1001(html, activeChar);
|
||||
send1002(activeChar, p.getCPost(0).postTxt, topic.getName(), DateFormat.getInstance().format(new Date(topic.getDate())));
|
||||
}
|
||||
|
||||
private void showMemoPost(Topic topic, L2PcInstance activeChar, Forum forum)
|
||||
{
|
||||
final Post p = getGPosttByTopic(topic);
|
||||
final Locale locale = Locale.getDefault();
|
||||
final DateFormat dateFormat = DateFormat.getDateInstance(DateFormat.FULL, locale);
|
||||
|
||||
String mes = p.getCPost(0).postTxt.replace(">", ">");
|
||||
mes = mes.replace("<", "<");
|
||||
|
||||
final String html = StringUtil.concat("<html><body><br><br><table border=0 width=610><tr><td width=10></td><td width=600 align=left><a action=\"bypass _bbshome\">HOME</a> > <a action=\"bypass _bbsmemo\">Memo Form</a></td></tr></table><img src=\"L2UI.squareblank\" width=\"1\" height=\"10\"><center><table border=0 cellspacing=0 cellpadding=0 bgcolor=333333><tr><td height=10></td></tr><tr><td fixWIDTH=55 align=right valign=top>&$413; : </td><td fixWIDTH=380 valign=top>", topic.getName(), "</td><td fixwidth=5></td><td fixwidth=50></td><td fixWIDTH=120></td></tr><tr><td height=10></td></tr><tr><td align=right><font color=\"AAAAAA\" >&$417; : </font></td><td><font color=\"AAAAAA\">", topic.getOwnerName() + "</font></td><td></td><td><font color=\"AAAAAA\">&$418; :</font></td><td><font color=\"AAAAAA\">", dateFormat.format(p.getCPost(0).postDate), "</font></td></tr><tr><td height=10></td></tr></table><br><table border=0 cellspacing=0 cellpadding=0><tr><td fixwidth=5></td><td FIXWIDTH=600 align=left>", mes, "</td><td fixqqwidth=5></td></tr></table><br><img src=\"L2UI.squareblank\" width=\"1\" height=\"5\"><img src=\"L2UI.squaregray\" width=\"610\" height=\"1\"><img src=\"L2UI.squareblank\" width=\"1\" height=\"5\"><table border=0 cellspacing=0 cellpadding=0 FIXWIDTH=610><tr><td width=50><button value=\"&$422;\" action=\"bypass _bbsmemo\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\"></td><td width=560 align=right><table border=0 cellspacing=0><tr><td FIXWIDTH=300></td><td><button value = \"&$424;\" action=\"bypass _bbsposts;edit;", String.valueOf(forum.getID()), ";", String.valueOf(topic.getID()), ";0\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td> <td><button value = \"&$425;\" action=\"bypass _bbstopics;del;", String.valueOf(forum.getID()), ";", String.valueOf(topic.getID()), "\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td> <td><button value = \"&$421;\" action=\"bypass _bbstopics;crea;", String.valueOf(forum.getID()), "\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td> </tr></table></td></tr></table><br><br><br></center></body></html>");
|
||||
CommunityBoardHandler.separateAndSend(html, activeChar);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parsewrite(String ar1, String ar2, String ar3, String ar4, String ar5, L2PcInstance activeChar)
|
||||
{
|
||||
final StringTokenizer st = new StringTokenizer(ar1, ";");
|
||||
final int idf = Integer.parseInt(st.nextToken());
|
||||
final int idt = Integer.parseInt(st.nextToken());
|
||||
final int idp = Integer.parseInt(st.nextToken());
|
||||
|
||||
final Forum f = ForumsBBSManager.getInstance().getForumByID(idf);
|
||||
if (f == null)
|
||||
{
|
||||
CommunityBoardHandler.separateAndSend("<html><body><br><br><center>the forum: " + idf + " does not exist !</center><br><br></body></html>", activeChar);
|
||||
}
|
||||
else
|
||||
{
|
||||
final Topic t = f.getTopic(idt);
|
||||
if (t == null)
|
||||
{
|
||||
CommunityBoardHandler.separateAndSend("<html><body><br><br><center>the topic: " + idt + " does not exist !</center><br><br></body></html>", activeChar);
|
||||
}
|
||||
else
|
||||
{
|
||||
final Post p = getGPosttByTopic(t);
|
||||
if (p != null)
|
||||
{
|
||||
final CPost cp = p.getCPost(idp);
|
||||
if (cp == null)
|
||||
{
|
||||
CommunityBoardHandler.separateAndSend("<html><body><br><br><center>the post: " + idp + " does not exist !</center><br><br></body></html>", activeChar);
|
||||
}
|
||||
else
|
||||
{
|
||||
p.getCPost(idp).postTxt = ar4;
|
||||
p.updatetxt(idp);
|
||||
parsecmd("_bbsposts;read;" + f.getID() + ";" + t.getID(), activeChar);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static PostBBSManager getInstance()
|
||||
{
|
||||
return SingletonHolder._instance;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final PostBBSManager _instance = new PostBBSManager();
|
||||
}
|
||||
}
|
@ -0,0 +1,323 @@
|
||||
/*
|
||||
* This file is part of the L2J Mobius project.
|
||||
*
|
||||
* 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.l2jmobius.gameserver.communitybbs.Manager;
|
||||
|
||||
import java.text.DateFormat;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.StringTokenizer;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import com.l2jmobius.gameserver.communitybbs.BB.Forum;
|
||||
import com.l2jmobius.gameserver.communitybbs.BB.Post;
|
||||
import com.l2jmobius.gameserver.communitybbs.BB.Topic;
|
||||
import com.l2jmobius.gameserver.data.sql.impl.ClanTable;
|
||||
import com.l2jmobius.gameserver.handler.CommunityBoardHandler;
|
||||
import com.l2jmobius.gameserver.model.actor.instance.L2PcInstance;
|
||||
import com.l2jmobius.util.StringUtil;
|
||||
|
||||
public class TopicBBSManager extends BaseBBSManager
|
||||
{
|
||||
private final List<Topic> _table = new CopyOnWriteArrayList<>();
|
||||
private final Map<Forum, Integer> _maxId = new HashMap<>();
|
||||
|
||||
protected TopicBBSManager()
|
||||
{
|
||||
// Prevent external initialization.
|
||||
}
|
||||
|
||||
public void addTopic(Topic tt)
|
||||
{
|
||||
_table.add(tt);
|
||||
}
|
||||
|
||||
public void delTopic(Topic topic)
|
||||
{
|
||||
_table.remove(topic);
|
||||
}
|
||||
|
||||
public void setMaxID(int id, Forum f)
|
||||
{
|
||||
_maxId.put(f, id);
|
||||
}
|
||||
|
||||
public int getMaxID(Forum f)
|
||||
{
|
||||
final Integer i = _maxId.get(f);
|
||||
if (i == null)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
public Topic getTopicByID(int idf)
|
||||
{
|
||||
for (Topic t : _table)
|
||||
{
|
||||
if (t.getID() == idf)
|
||||
{
|
||||
return t;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parsewrite(String ar1, String ar2, String ar3, String ar4, String ar5, L2PcInstance activeChar)
|
||||
{
|
||||
if (ar1.equals("crea"))
|
||||
{
|
||||
final Forum f = ForumsBBSManager.getInstance().getForumByID(Integer.parseInt(ar2));
|
||||
if (f == null)
|
||||
{
|
||||
CommunityBoardHandler.separateAndSend("<html><body><br><br><center>the forum: " + ar2 + " is not implemented yet</center><br><br></body></html>", activeChar);
|
||||
}
|
||||
else
|
||||
{
|
||||
f.vload();
|
||||
final Topic t = new Topic(Topic.ConstructorType.CREATE, TopicBBSManager.getInstance().getMaxID(f) + 1, Integer.parseInt(ar2), ar5, Calendar.getInstance().getTimeInMillis(), activeChar.getName(), activeChar.getObjectId(), Topic.MEMO, 0);
|
||||
f.addTopic(t);
|
||||
TopicBBSManager.getInstance().setMaxID(t.getID(), f);
|
||||
final Post p = new Post(activeChar.getName(), activeChar.getObjectId(), Calendar.getInstance().getTimeInMillis(), t.getID(), f.getID(), ar4);
|
||||
PostBBSManager.getInstance().addPostByTopic(p, t);
|
||||
parsecmd("_bbsmemo", activeChar);
|
||||
}
|
||||
}
|
||||
else if (ar1.equals("del"))
|
||||
{
|
||||
final Forum f = ForumsBBSManager.getInstance().getForumByID(Integer.parseInt(ar2));
|
||||
if (f == null)
|
||||
{
|
||||
CommunityBoardHandler.separateAndSend("<html><body><br><br><center>the forum: " + ar2 + " does not exist !</center><br><br></body></html>", activeChar);
|
||||
}
|
||||
else
|
||||
{
|
||||
final Topic t = f.getTopic(Integer.parseInt(ar3));
|
||||
if (t == null)
|
||||
{
|
||||
CommunityBoardHandler.separateAndSend("<html><body><br><br><center>the topic: " + ar3 + " does not exist !</center><br><br></body></html>", activeChar);
|
||||
}
|
||||
else
|
||||
{
|
||||
// CPost cp = null;
|
||||
final Post p = PostBBSManager.getInstance().getGPosttByTopic(t);
|
||||
if (p != null)
|
||||
{
|
||||
p.deleteme(t);
|
||||
}
|
||||
t.deleteme(f);
|
||||
parsecmd("_bbsmemo", activeChar);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CommunityBoardHandler.separateAndSend("<html><body><br><br><center>the command: " + ar1 + " is not implemented yet</center><br><br></body></html>", activeChar);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void parsecmd(String command, L2PcInstance activeChar)
|
||||
{
|
||||
if (command.equals("_bbsmemo"))
|
||||
{
|
||||
showTopics(activeChar.getMemo(), activeChar, 1, activeChar.getMemo().getID());
|
||||
}
|
||||
else if (command.startsWith("_bbstopics;read"))
|
||||
{
|
||||
final StringTokenizer st = new StringTokenizer(command, ";");
|
||||
st.nextToken();
|
||||
st.nextToken();
|
||||
final int idf = Integer.parseInt(st.nextToken());
|
||||
String index = null;
|
||||
if (st.hasMoreTokens())
|
||||
{
|
||||
index = st.nextToken();
|
||||
}
|
||||
int ind = 0;
|
||||
if (index == null)
|
||||
{
|
||||
ind = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
ind = Integer.parseInt(index);
|
||||
}
|
||||
showTopics(ForumsBBSManager.getInstance().getForumByID(idf), activeChar, ind, idf);
|
||||
}
|
||||
else if (command.startsWith("_bbstopics;crea"))
|
||||
{
|
||||
final StringTokenizer st = new StringTokenizer(command, ";");
|
||||
st.nextToken();
|
||||
st.nextToken();
|
||||
final int idf = Integer.parseInt(st.nextToken());
|
||||
showNewTopic(ForumsBBSManager.getInstance().getForumByID(idf), activeChar, idf);
|
||||
}
|
||||
else if (command.startsWith("_bbstopics;del"))
|
||||
{
|
||||
final StringTokenizer st = new StringTokenizer(command, ";");
|
||||
st.nextToken();
|
||||
st.nextToken();
|
||||
final int idf = Integer.parseInt(st.nextToken());
|
||||
final int idt = Integer.parseInt(st.nextToken());
|
||||
final Forum f = ForumsBBSManager.getInstance().getForumByID(idf);
|
||||
if (f == null)
|
||||
{
|
||||
CommunityBoardHandler.separateAndSend("<html><body><br><br><center>the forum: " + idf + " does not exist !</center><br><br></body></html>", activeChar);
|
||||
}
|
||||
else
|
||||
{
|
||||
final Topic t = f.getTopic(idt);
|
||||
if (t == null)
|
||||
{
|
||||
CommunityBoardHandler.separateAndSend("<html><body><br><br><center>the topic: " + idt + " does not exist !</center><br><br></body></html>", activeChar);
|
||||
}
|
||||
else
|
||||
{
|
||||
// CPost cp = null;
|
||||
final Post p = PostBBSManager.getInstance().getGPosttByTopic(t);
|
||||
if (p != null)
|
||||
{
|
||||
p.deleteme(t);
|
||||
}
|
||||
t.deleteme(f);
|
||||
parsecmd("_bbsmemo", activeChar);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
CommunityBoardHandler.separateAndSend("<html><body><br><br><center>the command: " + command + " is not implemented yet</center><br><br></body></html>", activeChar);
|
||||
}
|
||||
}
|
||||
|
||||
private void showNewTopic(Forum forum, L2PcInstance activeChar, int idf)
|
||||
{
|
||||
if (forum == null)
|
||||
{
|
||||
CommunityBoardHandler.separateAndSend("<html><body><br><br><center>the forum: " + idf + " is not implemented yet</center><br><br></body></html>", activeChar);
|
||||
}
|
||||
else if (forum.getType() == Forum.MEMO)
|
||||
{
|
||||
showMemoNewTopics(forum, activeChar);
|
||||
}
|
||||
else
|
||||
{
|
||||
CommunityBoardHandler.separateAndSend("<html><body><br><br><center>the forum: " + forum.getName() + " is not implemented yet</center><br><br></body></html>", activeChar);
|
||||
}
|
||||
}
|
||||
|
||||
private void showMemoNewTopics(Forum forum, L2PcInstance activeChar)
|
||||
{
|
||||
final String html = StringUtil.concat("<html><body><br><br><table border=0 width=610><tr><td width=10></td><td width=600 align=left><a action=\"bypass _bbshome\">HOME</a> > <a action=\"bypass _bbsmemo\">Memo Form</a></td></tr></table><img src=\"L2UI.squareblank\" width=\"1\" height=\"10\"><center><table border=0 cellspacing=0 cellpadding=0><tr><td width=610><img src=\"sek.cbui355\" width=\"610\" height=\"1\"><br1><img src=\"sek.cbui355\" width=\"610\" height=\"1\"></td></tr></table><table fixwidth=610 border=0 cellspacing=0 cellpadding=0><tr><td><img src=\"l2ui.mini_logo\" width=5 height=20></td></tr><tr><td><img src=\"l2ui.mini_logo\" width=5 height=1></td><td align=center FIXWIDTH=60 height=29>&$413;</td><td FIXWIDTH=540><edit var = \"Title\" width=540 height=13></td><td><img src=\"l2ui.mini_logo\" width=5 height=1></td></tr></table><table fixwidth=610 border=0 cellspacing=0 cellpadding=0><tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr><tr><td><img src=\"l2ui.mini_logo\" width=5 height=1></td><td align=center FIXWIDTH=60 height=29 valign=top>&$427;</td><td align=center FIXWIDTH=540><MultiEdit var =\"Content\" width=535 height=313></td><td><img src=\"l2ui.mini_logo\" width=5 height=1></td></tr><tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr></table><table fixwidth=610 border=0 cellspacing=0 cellpadding=0><tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr><tr><td><img src=\"l2ui.mini_logo\" width=5 height=1></td><td align=center FIXWIDTH=60 height=29> </td><td align=center FIXWIDTH=70><button value=\"&$140;\" action=\"Write Topic crea ", String.valueOf(forum.getID()), " Title Content Title\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td><td align=center FIXWIDTH=70><button value = \"&$141;\" action=\"bypass _bbsmemo\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\"> </td><td align=center FIXWIDTH=400> </td><td><img src=\"l2ui.mini_logo\" width=5 height=1></td></tr></table></center></body></html>");
|
||||
send1001(html, activeChar);
|
||||
send1002(activeChar);
|
||||
}
|
||||
|
||||
private void showTopics(Forum forum, L2PcInstance activeChar, int index, int idf)
|
||||
{
|
||||
if (forum == null)
|
||||
{
|
||||
CommunityBoardHandler.separateAndSend("<html><body><br><br><center>the forum: " + idf + " is not implemented yet</center><br><br></body></html>", activeChar);
|
||||
}
|
||||
else if (forum.getType() == Forum.MEMO)
|
||||
{
|
||||
showMemoTopics(forum, activeChar, index);
|
||||
}
|
||||
else
|
||||
{
|
||||
CommunityBoardHandler.separateAndSend("<html><body><br><br><center>the forum: " + forum.getName() + " is not implemented yet</center><br><br></body></html>", activeChar);
|
||||
}
|
||||
}
|
||||
|
||||
private void showMemoTopics(Forum forum, L2PcInstance activeChar, int index)
|
||||
{
|
||||
forum.vload();
|
||||
final StringBuilder html = StringUtil.startAppend(2000, "<html><body><br><br><table border=0 width=610><tr><td width=10></td><td width=600 align=left><a action=\"bypass _bbshome\">HOME</a> > <a action=\"bypass _bbsmemo\">Memo Form</a></td></tr></table><img src=\"L2UI.squareblank\" width=\"1\" height=\"10\"><center><table border=0 cellspacing=0 cellpadding=2 bgcolor=888888 width=610><tr><td FIXWIDTH=5></td><td FIXWIDTH=415 align=center>&$413;</td><td FIXWIDTH=120 align=center></td><td FIXWIDTH=70 align=center>&$418;</td></tr></table>");
|
||||
final DateFormat dateFormat = DateFormat.getInstance();
|
||||
|
||||
for (int i = 0, j = getMaxID(forum) + 1; i < (12 * index); j--)
|
||||
{
|
||||
if (j < 0)
|
||||
{
|
||||
break;
|
||||
}
|
||||
final Topic t = forum.getTopic(j);
|
||||
if (t != null)
|
||||
{
|
||||
if (i++ >= (12 * (index - 1)))
|
||||
{
|
||||
StringUtil.append(html, "<table border=0 cellspacing=0 cellpadding=5 WIDTH=610><tr><td FIXWIDTH=5></td><td FIXWIDTH=415><a action=\"bypass _bbsposts;read;", String.valueOf(forum.getID()), ";", String.valueOf(t.getID()), "\">", t.getName(), "</a></td><td FIXWIDTH=120 align=center></td><td FIXWIDTH=70 align=center>", dateFormat.format(new Date(t.getDate())), "</td></tr></table><img src=\"L2UI.Squaregray\" width=\"610\" height=\"1\">");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
html.append("<br><table width=610 cellspace=0 cellpadding=0><tr><td width=50><button value=\"&$422;\" action=\"bypass _bbsmemo\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\"></td><td width=510 align=center><table border=0><tr>");
|
||||
|
||||
if (index == 1)
|
||||
{
|
||||
html.append("<td><button action=\"\" back=\"l2ui_ch3.prev1_down\" fore=\"l2ui_ch3.prev1\" width=16 height=16 ></td>");
|
||||
}
|
||||
else
|
||||
{
|
||||
StringUtil.append(html, "<td><button action=\"bypass _bbstopics;read;", String.valueOf(forum.getID()), ";", String.valueOf(index - 1), "\" back=\"l2ui_ch3.prev1_down\" fore=\"l2ui_ch3.prev1\" width=16 height=16 ></td>");
|
||||
}
|
||||
|
||||
int nbp;
|
||||
nbp = forum.getTopicSize() / 8;
|
||||
if ((nbp * 8) != ClanTable.getInstance().getClanCount())
|
||||
{
|
||||
nbp++;
|
||||
}
|
||||
for (int i = 1; i <= nbp; i++)
|
||||
{
|
||||
if (i == index)
|
||||
{
|
||||
StringUtil.append(html, "<td> ", String.valueOf(i), " </td>");
|
||||
}
|
||||
else
|
||||
{
|
||||
StringUtil.append(html, "<td><a action=\"bypass _bbstopics;read;", String.valueOf(forum.getID()), ";", String.valueOf(i), "\"> ", String.valueOf(i), " </a></td>");
|
||||
}
|
||||
}
|
||||
if (index == nbp)
|
||||
{
|
||||
html.append("<td><button action=\"\" back=\"l2ui_ch3.next1_down\" fore=\"l2ui_ch3.next1\" width=16 height=16 ></td>");
|
||||
}
|
||||
else
|
||||
{
|
||||
StringUtil.append(html, "<td><button action=\"bypass _bbstopics;read;", String.valueOf(forum.getID()), ";", String.valueOf(index + 1), "\" back=\"l2ui_ch3.next1_down\" fore=\"l2ui_ch3.next1\" width=16 height=16 ></td>");
|
||||
}
|
||||
|
||||
StringUtil.append(html, "</tr></table> </td> <td align=right><button value = \"&$421;\" action=\"bypass _bbstopics;crea;", String.valueOf(forum.getID()), "\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\" ></td></tr><tr><td><img src=\"l2ui.mini_logo\" width=5 height=10></td></tr><tr> <td></td><td align=center><table border=0><tr><td></td><td><edit var = \"Search\" width=130 height=11></td><td><button value=\"&$420;\" action=\"Write 5 -2 0 Search _ _\" back=\"l2ui_ch3.smallbutton2_down\" width=65 height=20 fore=\"l2ui_ch3.smallbutton2\"> </td> </tr></table> </td></tr></table><br><br><br></center></body></html>");
|
||||
CommunityBoardHandler.separateAndSend(html.toString(), activeChar);
|
||||
}
|
||||
|
||||
public static TopicBBSManager getInstance()
|
||||
{
|
||||
return SingletonHolder._instance;
|
||||
}
|
||||
|
||||
private static class SingletonHolder
|
||||
{
|
||||
protected static final TopicBBSManager _instance = new TopicBBSManager();
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user