MapleStory Blogging System
PHP Code:
/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package org.anujan.server;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;
import org.anujan.client.MapleClient;
import org.anujan.database.DatabaseConnection;
import org.anujan.tools.Pair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/**
*
* @author Anujan
*/
public class BlogFactory {
private static Logger log = LoggerFactory.getLogger(BlogFactory.class);
private static BlogFactory instance;
private Map<Integer, List<Pair<String, String>>> blogs;
private static Runnable task;
public static BlogFactory getInstance() {
if (instance == null)
instance = new BlogFactory();
return instance;
}
private BlogFactory() {
task = new PersistingTask();
TimerManager.getInstance().register(task, 3 * 60 * 60 * 1000); // 3 Hours, change to your liking.
blogs = new HashMap<Integer, List<Pair<String, String>>>();
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = null;
ResultSet rs = null;
long startTime = System.currentTimeMillis();
int blogCount = 0;
try {
ps = con.prepareStatement("SELECT * FROM blogs");
rs = ps.executeQuery();
int characterid;
String blog;
String date;
while (rs.next()) {
characterid = rs.getInt("characterid");
blog = rs.getString("blog");
date = rs.getString("date");
if (!blogs.containsKey(characterid))
blogs.put(characterid, new ArrayList<Pair<String, String>>());
Pair blogg = new Pair<String, String>(blog, date);
blogs.get(characterid).add(blogg);
blogCount++;
}
} catch (SQLException sqle) {
log.error("SQL ERROR FOR BLOGS", sqle);
} finally {
if (ps != null)
ps.close();
if (rs != null)
rs.close();
}
log.info("Cached " + blogCount + " blogs in " + (System.currentTimeMillis() - startTime) / 1000 + " seconds");
}
public List<Pair<String, String>> getBlogs(int characterid) {
return blogs.get(characterid);
}
public boolean addBlog(MapleClient c, int characterid, String blog) {
if (System.currentTimeMillis() >= c.getNextBlogTime()) { //This can be removed if you want them be able to blog without a limit
blogs.get(characterid).add(new Pair<String, String>(blog, Calendar.getInstance().getTime().toString()));
return true;
}
return false;
}
public static class PersistingTask implements Runnable {
@Override
public void run() {
synchronized (blogs) {
Connection con = DatabaseConnection.getConnection();
PreparedStatement ps = null;
try {
ps = con.prepareStatement("DELETE FROM blogs");
ps.executeUpdate();
ps = con.prepareStatement("INSERT INTO blogs (characterid, blog, date) VALUES (?, ?, ?)");
for (Entry<Integer, List<Pair<String, String>>> blog : blogs.entrySet()) {
ps.setInt(1, blog.getKey());
for (Pair<String, String> entries : blog.getValue()) {
ps.setString(2, entries.getLeft());
ps.setString(3, entries.getRight());
ps.executeUpdate();
}
}
} catch (SQLException e) {
log.error("Error inserting blogs", e);
} finally {
if (ps != null)
ps.close();
}
}
}
}
}
It's not complete but the basic structure is complete.
Depends how you wanna add and view blogs.
That's up to you.
Feel free to modify/flame/whatever idc. :]
Re: MapleStory Blogging System
Re: MapleStory Blogging System
nice release by you !
---------- Post added at 02:04 AM ---------- Previous post was at 02:01 AM ----------
by the way still have anything left ?
Re: MapleStory Blogging System
3rd post Nice release looks good.
Re: MapleStory Blogging System
what does this do? create a blog ingame? o.o
Re: MapleStory Blogging System
Re: MapleStory Blogging System
Quote:
Originally Posted by
HeyitzStan
what does this do? create a blog ingame? o.o
Quote:
Originally Posted by
tsunayoshi
i think so
This is one of the reasons why flame exists.
Re: MapleStory Blogging System
Re: MapleStory Blogging System
Quote:
Originally Posted by
Traitor
Why? Why! WHY‽
Because if he didn't noobs would starve.
Re: MapleStory Blogging System
Quote:
Originally Posted by
WlZET
Because if he didn't noobs would starve.
dude you're the reason why flames exist, dont think you're pro and you can start saying shit to people. to be honest i dont even know who you are and what you have contributed to the community but if you think we're noobs, you're wrong. we are newbs, people who are new to coding. i simply asked, what this script does..whats so bad about asking something i dont know? cant expect an immigrant to enter the country to learn everything about it's language in 1 night.
dont get too cocky.
dont even say you arent, what you just said to us "newbs" is already being cocky.
get a life.
Re: MapleStory Blogging System
Re: MapleStory Blogging System
Quote:
Originally Posted by
HeyitzStan
dude you're the reason why flames exist, dont think you're pro and you can start saying shit to people. to be honest i dont even know who you are and what you have contributed to the community but if you think we're noobs, you're wrong. we are newbs, people who are new to coding. i simply asked, what this script does..whats so bad about asking something i dont know? cant expect an immigrant to enter the country to learn everything about it's language in 1 night.
dont get too cocky.
dont even say you arent, what you just said to us "newbs" is already being cocky.
get a life.
Yea, so that didn't help at all. He is just going to reply with a stupid remark or some flame that we don't care about. Just let it go. :glare:
Re: MapleStory Blogging System
Quote:
Originally Posted by
HeyitzStan
dude you're the reason why flames exist, dont think you're pro and you can start saying shit to people. to be honest i dont even know who you are and what you have contributed to the community but if you think we're noobs, you're wrong. we are newbs, people who are new to coding. i simply asked, what this script does..whats so bad about asking something i dont know? cant expect an immigrant to enter the country to learn everything about it's language in 1 night.
dont get too cocky.
dont even say you arent, what you just said to us "newbs" is already being cocky.
get a life.
Hey dude, hes a prao coders man.
Re: MapleStory Blogging System
Quote:
Originally Posted by
Celphius
Hey dude, hes a prao coders man.
So what?
Re: MapleStory Blogging System
Quote:
Originally Posted by
Traitor
Why? Why! WHY‽
because he did.