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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user