tobaJK

aCis Facebook System

Oct 26th, 2017 (edited)
981
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 42.24 KB | None | 0 0
  1. ### Eclipse Workspace Patch 1.0
  2. #P aCis_gameserver
  3. Index: java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java
  4. ===================================================================
  5. --- java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (revision 2)
  6. +++ java/net/sf/l2j/gameserver/handler/AdminCommandHandler.java (working copy)
  7. @@ -19,6 +19,7 @@
  8.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminEffects;
  9.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminEnchant;
  10.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminExpSp;
  11. +import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminFacebook;
  12.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminGeoEngine;
  13.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminGm;
  14.  import net.sf.l2j.gameserver.handler.admincommandhandlers.AdminGmChat;
  15. @@ -103,6 +104,7 @@
  16.         registerAdminCommandHandler(new AdminTarget());
  17.         registerAdminCommandHandler(new AdminTeleport());
  18.         registerAdminCommandHandler(new AdminZone());
  19. +       registerAdminCommandHandler(new AdminFacebook());
  20.     }
  21.    
  22.     public void registerAdminCommandHandler(IAdminCommandHandler handler)
  23. Index: java/net/sf/l2j/facebook/fb.java
  24. ===================================================================
  25. --- java/net/sf/l2j/facebook/fb.java    (nonexistent)
  26. +++ java/net/sf/l2j/facebook/fb.java    (working copy)
  27. @@ -0,0 +1,467 @@
  28. +package net.sf.l2j.facebook;
  29. +
  30. +import com.restfb.DefaultFacebookClient;
  31. +import com.restfb.FacebookClient;
  32. +import com.restfb.Parameter;
  33. +import com.restfb.exception.FacebookOAuthException;
  34. +import com.restfb.types.Page;
  35. +import com.restfb.types.Post;
  36. +
  37. +import java.sql.Connection;
  38. +import java.sql.PreparedStatement;
  39. +import java.sql.ResultSet;
  40. +import java.util.ArrayList;
  41. +import java.util.List;
  42. +import java.util.Set;
  43. +import java.util.concurrent.ConcurrentHashMap;
  44. +import java.util.concurrent.ScheduledFuture;
  45. +import java.util.logging.Logger;
  46. +
  47. +import net.sf.l2j.commons.concurrent.ThreadPool;
  48. +
  49. +import net.sf.l2j.Config;
  50. +import net.sf.l2j.L2DatabaseFactory;
  51. +import net.sf.l2j.gameserver.data.xml.AdminData;
  52. +import net.sf.l2j.gameserver.model.World;
  53. +import net.sf.l2j.gameserver.model.actor.instance.Player;
  54. +import net.sf.l2j.gameserver.network.clientpackets.Say2;
  55. +import net.sf.l2j.gameserver.network.serverpackets.CreatureSay;
  56. +
  57. +/**
  58. + * @author Melron
  59. + */
  60. +public class fb
  61. +{
  62. +   protected static final Logger LOG = Logger.getLogger(fb.class.getName());
  63. +  
  64. +   private static List<String> FACEBOOK_POSTS = new ArrayList<>();
  65. +  
  66. +   private static final String Facebook_Restore_Users_Ids = "SELECT facebook_user_id FROM characters where facebook_user_id IS NOT NULL";
  67. +   private static final String Facebook_Restore = "SELECT * FROM facebook";
  68. +  
  69. +   private static final Set<String> FACEBOOK_USERS_IDS = ConcurrentHashMap.newKeySet();
  70. +   private AutomaticReward _automaticReward;
  71. +  
  72. +   private static final int Normal = 0;
  73. +   private static final int Busy = 1;
  74. +   private static final int Error = 2;
  75. +   private static int position = Normal;
  76. +   protected ScheduledFuture<?> autoAnnounce = null;
  77. +  
  78. +   public enum State
  79. +   {
  80. +       Active,
  81. +       Inactive
  82. +   }
  83. +  
  84. +   public State state = State.Active;
  85. +  
  86. +   public static fb getInstance()
  87. +   {
  88. +       return SingletonHolder.INSTANCE;
  89. +   }
  90. +  
  91. +   private static class SingletonHolder
  92. +   {
  93. +       protected static final fb INSTANCE = new fb();
  94. +   }
  95. +  
  96. +   public fb()
  97. +   {
  98. +       load();
  99. +   }
  100. +  
  101. +   public void load()
  102. +   {
  103. +       state = State.Active;
  104. +       position = Normal;
  105. +       loadLinksAndToken();
  106. +       LOG.warning("Loadded " + FACEBOOK_USERS_IDS.size() + " Facebook Users Ids");
  107. +      
  108. +   }
  109. +  
  110. +   public void setFbState(State _state)
  111. +   {
  112. +       state = _state;
  113. +   }
  114. +  
  115. +   public AutomaticReward setAutomaticReward(AutomaticReward reward)
  116. +   {
  117. +       _automaticReward = reward;
  118. +       return _automaticReward;
  119. +   }
  120. +  
  121. +   public AutomaticReward getAutomaticReward()
  122. +   {
  123. +       return _automaticReward;
  124. +   }
  125. +  
  126. +  
  127. +   public void reload(Player activeChar)
  128. +   {
  129. +       try
  130. +       {
  131. +           FACEBOOK_POSTS.clear();
  132. +           FACEBOOK_USERS_IDS.clear();
  133. +           load();
  134. +           if (activeChar != null)
  135. +               activeChar.sendPacket(new CreatureSay(0, Say2.CRITICAL_ANNOUNCE, "Facebook", "Facebook: Successfully reloaded."));
  136. +       }
  137. +       catch (Exception e)
  138. +       {
  139. +           if (activeChar != null)
  140. +               activeChar.sendPacket(new CreatureSay(0, Say2.CRITICAL_ANNOUNCE, "Facebook", "Facebook: There was an error while restoring facebook data."));
  141. +       }
  142. +   }
  143. +  
  144. +  
  145. +   public List<String> getFacebookPages()
  146. +   {
  147. +       return FACEBOOK_POSTS;
  148. +   }
  149. +  
  150. +  
  151. +   private static void loadLinksAndToken()
  152. +   {
  153. +       try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  154. +       {
  155. +           PreparedStatement statement = con.prepareStatement(Facebook_Restore);
  156. +           ResultSet rset = statement.executeQuery();
  157. +          
  158. +           while (rset.next())
  159. +           {
  160. +               if (FACEBOOK_POSTS.contains(rset.getString("enc_link")))
  161. +                   System.out.println("WARNING! Facebook ERROR! Double link found in database (facebook table)");
  162. +               else
  163. +                   FACEBOOK_POSTS.add(rset.getString("enc_link"));
  164. +              
  165. +           }
  166. +           rset.close();
  167. +           statement.close();
  168. +          
  169. +           statement = con.prepareStatement(Facebook_Restore_Users_Ids);
  170. +           rset = statement.executeQuery();
  171. +          
  172. +           while (rset.next())
  173. +           {
  174. +               if (FACEBOOK_USERS_IDS.contains(rset.getString("facebook_user_id")))
  175. +                   System.out.println("WARNING! Facebook ERROR! Double user id {" + rset.getString("facebook_user_id") + "}");
  176. +               else
  177. +                   FACEBOOK_USERS_IDS.add(rset.getString("facebook_user_id"));
  178. +           }
  179. +          
  180. +           rset.close();
  181. +           statement.close();
  182. +           Config.loadFacebook();
  183. +       }
  184. +       catch (Exception e)
  185. +       {
  186. +           System.out.println("Facebook Error: " + e.getMessage());
  187. +           e.printStackTrace();
  188. +       }
  189. +      
  190. +       System.out.println("Facebook settings has been successfully loaded.");
  191. +   }
  192. +  
  193. +   /**
  194. +    * @param player
  195. +    * @param fbName
  196. +    * @return true/false
  197. +    */
  198. +   public boolean acceptName(Player player, String fbName)
  199. +   {
  200. +       if (fbName != null && fbName.length() > 0)
  201. +       {
  202. +           player.setFacebookName(fbName, true);
  203. +           return true;
  204. +       }
  205. +       return false;
  206. +   }
  207. +  
  208. +   /**
  209. +    * @param activeChar
  210. +    */
  211. +   public void executeFacebookCheck(Player activeChar)
  212. +   {
  213. +       if (activeChar == null)
  214. +           return;
  215. +      
  216. +       if (activeChar.getFacebookName() == null)
  217. +       {
  218. +           activeChar.sendMessage("You must set your facebook user name first!");
  219. +           return;
  220. +       }
  221. +      
  222. +       if (state == State.Inactive)
  223. +       {
  224. +           activeChar.sendMessage("Facebook system is currently under maintenance..");
  225. +           return;
  226. +       }
  227. +       if (position == Busy)
  228. +       {
  229. +           activeChar.sendMessage("Do not move so fast...");
  230. +           return;
  231. +       }
  232. +       if (position == Error)
  233. +       {
  234. +           activeChar.sendMessage("Something is going wrong. Please wait until the administrator solve this problem.");
  235. +           return;
  236. +       }
  237. +      
  238. +       position = Busy;
  239. +      
  240. +       int currentLikes = 0;
  241. +       int WantedLikes = getFacebookPages().size();
  242. +       if (WantedLikes == 0)
  243. +       {
  244. +           activeChar.sendMessage("Something is going wrong. please contact with the administrator!");
  245. +           position = Error;
  246. +           return;
  247. +       }
  248. +       try
  249. +       {
  250. +           @SuppressWarnings("deprecation")
  251. +           FacebookClient fClient = new DefaultFacebookClient(Config.FACEBOOK_API_TOKEN);
  252. +          
  253. +           for (String page : getFacebookPages())
  254. +           {
  255. +               com.restfb.Connection<Page> result = fClient.fetchConnection(page + "/likes", Page.class);
  256. +              
  257. +               for (List<Page> pages : result)
  258. +                   for (Page likePage : pages)
  259. +                       if (likePage.getName().equals(activeChar.getFacebookName()))
  260. +                       {
  261. +                           if (likePage.getId().equals(activeChar.getFacebookUserId()))
  262. +                           {
  263. +                               currentLikes++;
  264. +                               break;
  265. +                           }
  266. +                           if (activeChar.getFacebookUserId() == null && !FACEBOOK_USERS_IDS.contains(likePage.getId()))
  267. +                           {
  268. +                               FACEBOOK_USERS_IDS.add(likePage.getId());
  269. +                               activeChar.setFacebookUserId(likePage.getId(), true);
  270. +                               currentLikes++;
  271. +                               break;
  272. +                           }
  273. +                       }
  274. +                  
  275. +           }
  276. +       }
  277. +       catch (FacebookOAuthException e)
  278. +       {
  279. +           position = Error;
  280. +           LOG.warning(e.getErrorMessage());
  281. +           e.printStackTrace();
  282. +       }
  283. +       if (currentLikes == WantedLikes)
  284. +       {
  285. +           activeChar.saveLikes();
  286. +           activeChar.sendMessage("You have successfully liked all the facebook posts!");
  287. +           activeChar.addItem("Fb-Reward", Config.FACEBOOK_REWARD_ID, Config.FACEBOOK_REWARD_COUNT, null, true);
  288. +       }
  289. +       else
  290. +       {
  291. +           activeChar.sendMessage(currentLikes == 0 ? "You haven't liked any post..." : "You have to like " + (WantedLikes - currentLikes) + " more posts in order to take your reward!");
  292. +       }
  293. +       position = Normal;
  294. +   }
  295. +  
  296. +   public int getTotalLikes()
  297. +   {
  298. +       int likes = 0;
  299. +       try
  300. +       {
  301. +           @SuppressWarnings("deprecation")
  302. +           FacebookClient fClient = new DefaultFacebookClient(Config.FACEBOOK_API_TOKEN);
  303. +          
  304. +           com.restfb.Connection<Post> result = fClient.fetchConnection(Config.FACEBOOK_PAGE_NAME + "/feed", Post.class);
  305. +          
  306. +           for (List<Post> page : result)
  307. +           {
  308. +               for (Post aPost : page)
  309. +                   if (FACEBOOK_POSTS.contains(aPost.getId()))
  310. +                   {
  311. +                       aPost = fClient.fetchObject(aPost.getId(), Post.class, Parameter.with("fields", "from,actions,message,story,to,likes.limit(0).summary(true),comments.limit(0).summary(true),shares.limit(0).summary(true)"));
  312. +                       likes += aPost.getLikesCount();
  313. +                   }
  314. +           }
  315. +          
  316. +       }
  317. +       catch (FacebookOAuthException e)
  318. +       {
  319. +           LOG.warning(e.getErrorMessage());
  320. +           e.printStackTrace();
  321. +       }
  322. +       return likes;
  323. +   }
  324. +  
  325. +   /**
  326. +    * @return
  327. +    */
  328. +   public State getState()
  329. +   {
  330. +       return state;
  331. +   }
  332. +  
  333. +   /**
  334. +    * @return
  335. +    */
  336. +   public List<Post> getAllPosts()
  337. +   {
  338. +       List<Post> allPosts = new ArrayList<>();
  339. +       String token = Config.FACEBOOK_API_TOKEN;
  340. +       try
  341. +       {
  342. +          
  343. +           @SuppressWarnings("deprecation")
  344. +           FacebookClient fClient = new DefaultFacebookClient(token);
  345. +          
  346. +           com.restfb.Connection<Post> result = fClient.fetchConnection(Config.FACEBOOK_PAGE_NAME + "/feed", Post.class);
  347. +          
  348. +           for (List<Post> page : result)
  349. +           {
  350. +               for (Post aPost : page)
  351. +               {
  352. +                   allPosts.add(aPost);
  353. +                  
  354. +               }
  355. +           }
  356. +          
  357. +       }
  358. +       catch (Exception e)
  359. +       {
  360. +           e.printStackTrace();
  361. +          
  362. +       }
  363. +       return allPosts;
  364. +   }
  365. +  
  366. +   public void savePost(String postId, String postName, Player activeChar)
  367. +   {
  368. +       try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  369. +       {
  370. +           PreparedStatement statement = con.prepareStatement("INSERT INTO facebook VALUES (?)");
  371. +           statement.setString(1, postId);
  372. +           statement.execute();
  373. +           statement.close();
  374. +           FACEBOOK_POSTS.add(postId);
  375. +           if (activeChar != null)
  376. +               activeChar.sendMessage("New post has been added.");
  377. +       }
  378. +       catch (Exception e)
  379. +       {
  380. +           LOG.warning("Could not insert new post in db: " + e);
  381. +       }
  382. +   }
  383. +  
  384. +   public void removePost(String postId, String postMessage, Player activeChar)
  385. +   {
  386. +       try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  387. +       {
  388. +           PreparedStatement statement = con.prepareStatement("DELETE FROM facebook WHERE enc_link=?");
  389. +           statement.setString(1, postId);
  390. +           statement.execute();
  391. +           statement.close();
  392. +           FACEBOOK_POSTS.remove(postId);
  393. +           activeChar.sendMessage("Post has been deleted.");
  394. +       }
  395. +       catch (Exception e)
  396. +       {
  397. +           LOG.warning("could not delete post from db: " + e);
  398. +       }
  399. +      
  400. +   }
  401. +  
  402. +   /**
  403. +    * @param name
  404. +    * @return
  405. +    */
  406. +   public boolean postExists(String name)
  407. +   {
  408. +       return FACEBOOK_POSTS.contains(name);
  409. +   }
  410. +  
  411. +   public void cleanFacebookData()
  412. +   {
  413. +       try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  414. +       {
  415. +           final String[] statements =
  416. +           {
  417. +               "TRUNCATE TABLE facebook",
  418. +               "UPDATE characters SET facebook_name = null,facebook_user_id = null,facebookliked = 0"
  419. +           };
  420. +           PreparedStatement statement;
  421. +           for (String statementStr : statements)
  422. +           {
  423. +               statement = con.prepareStatement(statementStr);
  424. +               statement.execute();
  425. +               statement.close();
  426. +           }
  427. +          
  428. +           for (Player player : World.getInstance().getPlayers())
  429. +           {
  430. +               if (player != null)
  431. +               {
  432. +                   player.setFacebookName(null, false);
  433. +                   player.setFacebookUserId(null, false);
  434. +               }
  435. +           }
  436. +           AdminData.getInstance().broadcastMessageToGMs("Facebook session has reset.");
  437. +       }
  438. +       catch (Exception e)
  439. +       {
  440. +           LOG.warning("could not reset facebook data in characters from db: " + e);
  441. +           e.printStackTrace();
  442. +           AdminData.getInstance().broadcastMessageToGMs("Facebook session reset failed.");
  443. +       }
  444. +   }
  445. +  
  446. +   public void turn(boolean on)
  447. +   {
  448. +       state = on ? State.Active : State.Inactive;
  449. +       AdminData.getInstance().broadcastMessageToGMs("Facebook system is now " + (on ? "On" : "Off"));
  450. +   }
  451. +  
  452. +   public void setAutoAnnounce(boolean val)
  453. +   {
  454. +       if (val)
  455. +       {
  456. +           if (autoAnnounce != null)
  457. +           {
  458. +               AdminData.getInstance().broadcastMessageToGMs("Error, AutoAnnounce is running");
  459. +               return;
  460. +           }
  461. +           AdminData.getInstance().broadcastMessageToGMs("Facebook Auto-Announcements started.");
  462. +           autoAnnounce = ThreadPool.scheduleAtFixedRate(new Runnable()
  463. +           {
  464. +               @Override
  465. +               public void run()
  466. +               {
  467. +                   for (Player player : World.getInstance().getPlayers())
  468. +                       if (player != null && getState() == State.Active)
  469. +                           player.sendPacket(new CreatureSay(0, Say2.CRITICAL_ANNOUNCE, "Facebook", "Dont forget to like in order to get our reward!"));
  470. +                      
  471. +               }
  472. +              
  473. +           }, 5000, 5000);
  474. +       }
  475. +       else
  476. +       {
  477. +           if (autoAnnounce != null)
  478. +           {
  479. +               AdminData.getInstance().broadcastMessageToGMs("Facebook Auto-Announcements canceled.");
  480. +               autoAnnounce.cancel(true);
  481. +               autoAnnounce = null;
  482. +           }
  483. +       }
  484. +      
  485. +   }
  486. +  
  487. +   /**
  488. +    * @return
  489. +    */
  490. +   public boolean isAutoAnnounceOn()
  491. +   {
  492. +       return autoAnnounce != null;
  493. +   }
  494. +}
  495. \ No newline at end of file
  496. Index: java/net/sf/l2j/facebook/AutomaticReward.java
  497. ===================================================================
  498. --- java/net/sf/l2j/facebook/AutomaticReward.java   (nonexistent)
  499. +++ java/net/sf/l2j/facebook/AutomaticReward.java   (working copy)
  500. @@ -0,0 +1,104 @@
  501. +package net.sf.l2j.facebook;
  502. +
  503. +import java.util.concurrent.ScheduledFuture;
  504. +
  505. +import net.sf.l2j.commons.concurrent.ThreadPool;
  506. +
  507. +import net.sf.l2j.gameserver.data.xml.AdminData;
  508. +import net.sf.l2j.gameserver.model.World;
  509. +import net.sf.l2j.gameserver.model.actor.instance.Player;
  510. +
  511. +/**
  512. + * @author Melron
  513. + */
  514. +public class AutomaticReward
  515. +{
  516. +   private  int itemId;
  517. +   private  int itemCnt;
  518. +   private  int likes;
  519. +   private  boolean enabled = false;
  520. +   protected  boolean rewarded = false;
  521. +  
  522. +   protected ScheduledFuture<?> checkTask;
  523. +  
  524. +   public AutomaticReward(int id, int count, int whenLikes)
  525. +   {
  526. +       itemId = id;
  527. +       itemCnt = count;
  528. +       likes = whenLikes;
  529. +       enabled = true;
  530. +   }
  531. +  
  532. +   public boolean isRewarded()
  533. +   {
  534. +       return rewarded;
  535. +   }
  536. +  
  537. +   public int getItemId()
  538. +   {
  539. +       return itemId;
  540. +   }
  541. +  
  542. +   public int getItemCnt()
  543. +   {
  544. +       return itemCnt;
  545. +   }
  546. +  
  547. +   public int getLikesCount()
  548. +   {
  549. +       return likes;
  550. +   }
  551. +  
  552. +   public boolean isEnabled()
  553. +   {
  554. +       return enabled;
  555. +   }
  556. +  
  557. +   public void start()
  558. +   {
  559. +       enabled = true;
  560. +       checkTask = ThreadPool.scheduleAtFixedRate(new Runnable()
  561. +       {
  562. +           @Override
  563. +           public void run()
  564. +           {
  565. +               if (reward())
  566. +               {
  567. +                   rewarded = true;
  568. +                   end();
  569. +               }
  570. +              
  571. +           }
  572. +          
  573. +       }, 5000, 5000);
  574. +   }
  575. +  
  576. +   protected void end()
  577. +   {
  578. +       if (checkTask != null)
  579. +       {
  580. +           checkTask.cancel(true);
  581. +           checkTask = null;
  582. +       }
  583. +       AdminData.getInstance().broadcastMessageToGMs("Automatic facebook reward successfully launched and rewarded.");
  584. +   }
  585. +  
  586. +   protected boolean reward()
  587. +   {
  588. +       if (fb.getInstance().getTotalLikes() >= likes)
  589. +       {
  590. +           rewarded = true;
  591. +           for (Player player : World.getInstance().getPlayers())
  592. +           {
  593. +               if (player != null)
  594. +               {
  595. +                   player.addItem("fb-reward", itemId, itemCnt, null, true);
  596. +                   player.sendMessage("Facebook Reward!!");
  597. +               }
  598. +           }
  599. +           return rewarded;
  600. +       }
  601. +       return false;
  602. +   }
  603. +  
  604. +}
  605.  
  606. Index: java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminFacebook.java
  607. ===================================================================
  608. --- java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminFacebook.java  (nonexistent)
  609. +++ java/net/sf/l2j/gameserver/handler/admincommandhandlers/AdminFacebook.java  (working copy)
  610. @@ -0,0 +1,265 @@
  611. +package net.sf.l2j.gameserver.handler.admincommandhandlers;
  612. +
  613. +import com.restfb.types.Post;
  614. +
  615. +import java.util.List;
  616. +import java.util.StringTokenizer;
  617. +
  618. +import net.sf.l2j.commons.concurrent.ThreadPool;
  619. +import net.sf.l2j.commons.lang.StringUtil;
  620. +
  621. +import net.sf.l2j.facebook.fb;
  622. +import net.sf.l2j.facebook.fb.State;
  623. +import net.sf.l2j.gameserver.handler.IAdminCommandHandler;
  624. +import net.sf.l2j.gameserver.model.actor.instance.Player;
  625. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  626. +
  627. +/**
  628. + * This class handles following admin commands:
  629. + * <ul>
  630. + * <li>ban_acc [account_name] = changes account access level to -100 and logs him off. If no account is specified target's account is used.</li>
  631. + * <li>ban_char [char_name] = changes a characters access level to -100 and logs him off. If no character is specified target is used.</li>
  632. + * <li>ban_chat [char_name] [duration] = chat bans a character for the specified duration. If no name is specified the target is chat banned indefinitely.</li>
  633. + * <li>unban_acc [account_name] = changes account access level to 0.</li>
  634. + * <li>unban_char [char_name] = changes specified characters access level to 0.</li>
  635. + * <li>unban_chat [char_name] = lifts chat ban from specified player. If no player name is specified current target is used.</li>
  636. + * <li>jail [char_name] [penalty_time] = jails character. Time specified in minutes. For ever if no time is specified.</li>
  637. + * <li>unjail [char_name] = Unjails player, teleport him to Floran.</li>
  638. + * </ul>
  639. + */
  640. +public class AdminFacebook implements IAdminCommandHandler
  641. +{
  642. +   private static final String[] ADMIN_COMMANDS =
  643. +   {
  644. +       "admin_facebook",
  645. +       "admin_showPosts",
  646. +       "admin_delPost",
  647. +       "admin_addPost",
  648. +       "admin_turnFb",
  649. +       "admin_fbreload",
  650. +       "admin_fb_auto_announce",
  651. +       "admin_clean_facebook_database"
  652. +   };
  653. +  
  654. +   @Override
  655. +   public boolean useAdminCommand(String command, Player activeChar)
  656. +   {
  657. +       if (command.startsWith("admin_facebook"))
  658. +       {
  659. +           pendingHtml(activeChar);
  660. +           ThreadPool.schedule(() -> sendHtml(activeChar), 1);
  661. +       }
  662. +       else if (command.startsWith("admin_clean_facebook_database"))
  663. +       {
  664. +           fb.getInstance().cleanFacebookData();
  665. +       }
  666. +       else if (command.startsWith("admin_fbreload"))
  667. +       {
  668. +           fb.getInstance().reload(activeChar);
  669. +       }
  670. +       else if (command.startsWith("admin_fb_auto_announce"))
  671. +       {
  672. +           StringTokenizer st = new StringTokenizer(command);
  673. +           st.nextToken();
  674. +           boolean choice = Boolean.parseBoolean(st.nextToken());
  675. +           fb.getInstance().setAutoAnnounce(choice);
  676. +           ThreadPool.schedule(() -> sendHtml(activeChar), 1);
  677. +       }
  678. +       else if (command.startsWith("admin_turnFb "))
  679. +       {
  680. +           boolean choice = Boolean.parseBoolean(command.substring(13));
  681. +           fb.getInstance().turn(choice);
  682. +           pendingHtml(activeChar);
  683. +           ThreadPool.schedule(() -> sendHtml(activeChar), 1);
  684. +       }
  685. +       else if (command.startsWith("admin_showPosts"))
  686. +       {
  687. +           ThreadPool.schedule(() -> showPosts(activeChar), 1);
  688. +       }
  689. +       else if (command.startsWith("admin_addPost"))
  690. +       {
  691. +           StringTokenizer st = new StringTokenizer(command, " ");
  692. +           st.nextToken();
  693. +          
  694. +           if (!st.hasMoreTokens())
  695. +           {
  696. +               activeChar.sendMessage("Error in command bypass " + command);
  697. +               return false;
  698. +           }
  699. +           String postId = st.nextToken();
  700. +           String postName = st.nextToken();
  701. +           if (fb.getInstance().postExists(postId))
  702. +           {
  703. +               activeChar.sendMessage("post already added.");
  704. +               return false;
  705. +           }
  706. +          
  707. +           fb.getInstance().savePost(postId, postName, activeChar);
  708. +           ThreadPool.schedule(() -> showPosts(activeChar), 1);
  709. +       }
  710. +       else if (command.startsWith("admin_delPost"))
  711. +       {
  712. +           StringTokenizer st = new StringTokenizer(command, " ");
  713. +           st.nextToken();
  714. +          
  715. +           if (!st.hasMoreTokens())
  716. +           {
  717. +               activeChar.sendMessage("Error in command bypass " + command);
  718. +               return false;
  719. +           }
  720. +           String postId = st.nextToken();
  721. +           String postName = st.nextToken();
  722. +           fb.getInstance().removePost(postId, postName, activeChar);
  723. +           ThreadPool.schedule(() -> showPosts(activeChar), 1);
  724. +       }
  725. +       return true;
  726. +   }
  727. +  
  728. +   private static void pendingHtml(Player activeChar)
  729. +   {
  730. +       if (activeChar != null)
  731. +       {
  732. +           final NpcHtmlMessage html = new NpcHtmlMessage(0);
  733. +           html.setFile("data/html/facebook/gmFB-pending.htm");
  734. +           activeChar.sendPacket(html);
  735. +       }
  736. +   }
  737. +  
  738. +   /**
  739. +    * @param activeChar
  740. +    */
  741. +   private static void showPosts(Player activeChar)
  742. +   {
  743. +       if (activeChar == null)
  744. +           return;
  745. +      
  746. +       final NpcHtmlMessage html = new NpcHtmlMessage(0);
  747. +       html.setFile("data/html/facebook/posts.htm");
  748. +       html.replace("%posts%", makePosts(fb.getInstance().getAllPosts()));
  749. +       activeChar.sendPacket(html);
  750. +   }
  751. +  
  752. +   /**
  753. +    * @param allPosts
  754. +    * @return
  755. +    */
  756. +   private static String makePosts(List<Post> allPosts)
  757. +   {
  758. +       if (allPosts.isEmpty())
  759. +           return "";
  760. +      
  761. +       final StringBuilder sb = new StringBuilder();
  762. +      
  763. +       for (Post post : allPosts)
  764. +       {
  765. +           if (fb.getInstance().postExists(post.getId()))
  766. +               StringUtil.append(sb, "<tr><td>", checkForBigString(post.getMessage()), "</td><td><a action=\"bypass admin_delPost ", post.getId(), " ", post.getMessage(), "\"><font color=\"CB440A\">Remove</font></a></td></tr>");
  767. +           else
  768. +               StringUtil.append(sb, "<tr><td>", checkForBigString(post.getMessage()), "</td><td><a action=\"bypass admin_addPost ", post.getId(), " ", post.getMessage(), "\"><font color=\"0E772C\">Add</font></a></td></tr>");
  769. +          
  770. +       }
  771. +      
  772. +       return sb.toString();
  773. +   }
  774. +  
  775. +   /**
  776. +    * @param message
  777. +    * @return
  778. +    */
  779. +   private static String checkForBigString(String message)
  780. +   {
  781. +       if (message.length() > 25)
  782. +       {
  783. +           String[] words = message.split(" ");
  784. +           if (words.length > 4)
  785. +               return new String(words[0] + " " + words[1] + " " + words[2] + " ... " + words[words.length - 1]);
  786. +           return message;
  787. +       }
  788. +       return message;
  789. +   }
  790. +  
  791. +   private static void sendHtml(Player activeChar)
  792. +   {
  793. +       if (activeChar == null || !activeChar.isGM())
  794. +           return;
  795. +      
  796. +       final NpcHtmlMessage html = new NpcHtmlMessage(0);
  797. +       html.setFile("data/html/facebook/gmFB.htm");
  798. +       if (fb.getInstance().getState() == State.Active)
  799. +       {
  800. +           html.replace("%facebookState%", "<img src=L2UI_CH3.radar_party width=8 height=8>");
  801. +           html.replace("%isEnabled%", "<button value=\"\" action=\"bypass admin_turnFb false\" width=16 height=16 fore=\"l2ui.CheckBox_checked\" back=\"l2ui.CheckBox_unable\">");
  802. +          
  803. +       }
  804. +       else
  805. +       {
  806. +           html.replace("%facebookState%", "<img src=L2UI_CH3.radar_target width=8 height=8>");
  807. +           html.replace("%isEnabled%", "<button value=\"\" action=\"bypass admin_turnFb true\" width=16 height=16 fore=\"l2ui.CheckBox_unable\" back=\"l2ui.CheckBox_checked\">");
  808. +       }
  809. +       html.replace("%totalLikes%", fb.getInstance().getTotalLikes());
  810. +       html.replace("%pages%", fb.getInstance().getFacebookPages().size());
  811. +       if (fb.getInstance().isAutoAnnounceOn())
  812. +           html.replace("%autoAnnounce%", "<button value=\"\" action=\"bypass admin_fb_auto_announce false\" width=16 height=16 fore=\"l2ui.CheckBox_checked\" back=\"l2ui.CheckBox_unable\">");
  813. +       else
  814. +           html.replace("%autoAnnounce%", "<button value=\"\" action=\"bypass admin_fb_auto_announce true\" width=16 height=16 fore=\"l2ui.CheckBox_unable\" back=\"l2ui.CheckBox_checked\">");
  815. +      
  816. +       if (fb.getInstance().getAutomaticReward() == null)
  817. +       {
  818. +           html.replace("%automaticRewardState%", "<font color=\"DE320C\"> Disabled </font>");
  819. +           html.replace("%automaticRewardTick%", "<img src=l2ui.CheckBox_unable width=16 height=16>");
  820. +           html.replace("%likesNum%", 0);
  821. +           html.replace("%idNum%", 0);
  822. +           html.replace("%cntNum%", 0);
  823. +       }
  824. +       else
  825. +       {
  826. +           boolean enabled = fb.getInstance().getAutomaticReward().isEnabled();
  827. +           boolean rewarded = enabled && fb.getInstance().getAutomaticReward().isRewarded();
  828. +          
  829. +           int likes = fb.getInstance().getAutomaticReward().getLikesCount();
  830. +           int id = fb.getInstance().getAutomaticReward().getItemId();
  831. +           int cnt = fb.getInstance().getAutomaticReward().getItemCnt();
  832. +          
  833. +           if (enabled)
  834. +           {
  835. +               if (rewarded)
  836. +               {
  837. +                   html.replace("%automaticRewardState%", "<font color=\"CBCB04\"> Rewarded </font>");
  838. +                   html.replace("%automaticRewardTick%", "<img src=l2ui.CheckBox_checked width=16 height=16>");
  839. +                  
  840. +                   html.replace("%likesNum%", "<font color=\"CBCB04\">" + likes + "</font>");
  841. +                   html.replace("%idNum%", "<font color=\"CBCB04\">" + id + "</font>");
  842. +                   html.replace("%cntNum%", "<font color=\"CBCB04\">" + cnt + "</font>");
  843. +               }
  844. +               else
  845. +               {
  846. +                   html.replace("%automaticRewardState%", "<font color=\"10D548\"> Enabled </font>");
  847. +                   html.replace("%automaticRewardTick%", "<img src=l2ui.CheckBox_checked_unable width=16 height=16>");
  848. +                  
  849. +                   html.replace("%likesNum%", "<font color=\"10D548\">" + likes + "</font>");
  850. +                   html.replace("%idNum%", "<font color=\"10D548\">" + id + "</font>");
  851. +                   html.replace("%cntNum%", "<font color=\"10D548\">" + cnt + "</font>");
  852. +                  
  853. +               }
  854. +           }
  855. +           else
  856. +           {
  857. +               html.replace("%automaticRewardState%", "<font color=\"DE320C\"> Disabled </font>");
  858. +               html.replace("%automaticRewardTick%", "<img src=l2ui.CheckBox_unable width=16 height=16>");
  859. +               html.replace("%likesNum%", 0);
  860. +               html.replace("%idNum%", 0);
  861. +               html.replace("%cntNum%", 0);
  862. +           }
  863. +          
  864. +       }
  865. +      
  866. +       activeChar.sendPacket(html);
  867. +      
  868. +   }
  869. +  
  870. +   @Override
  871. +   public String[] getAdminCommandList()
  872. +   {
  873. +       return ADMIN_COMMANDS;
  874. +   }
  875. +}
  876. \ No newline at end of file
  877. Index: java/net/sf/l2j/Config.java
  878. ===================================================================
  879. --- java/net/sf/l2j/Config.java (revision 2)
  880. +++ java/net/sf/l2j/Config.java (working copy)
  881. @@ -37,7 +37,11 @@
  882.     public static final String PLAYERS_FILE = "./config/players.properties";
  883.     public static final String SERVER_FILE = "./config/server.properties";
  884.     public static final String SIEGE_FILE = "./config/siege.properties";
  885. +   public static final String FACEBOOK_FILE = "./config/facebook.properties";
  886.    
  887. +   public static String FACEBOOK_API_TOKEN;
  888. +   public static String FACEBOOK_PAGE_NAME;
  889. +   public static int FACEBOOK_REWARD_ID;
  890. +   public static int FACEBOOK_REWARD_COUNT;
  891. +  
  892.     // --------------------------------------------------
  893.     // Clans settings
  894.     // --------------------------------------------------
  895. @@ -718,6 +722,17 @@
  896.     /**
  897.      * Loads clan and clan hall settings.
  898.      */
  899. +   public static final void loadFacebook()
  900. +   {
  901. +       final ExProperties fb = initProperties(FACEBOOK_FILE);
  902. +      
  903. +       FACEBOOK_API_TOKEN = fb.getProperty("FacebookApiToken", "123");
  904. +       FACEBOOK_PAGE_NAME = fb.getProperty("FacebookPageName" , "L2Tests");
  905. +       FACEBOOK_REWARD_ID = fb.getProperty("FacebookRewardId" , 57);
  906. +       FACEBOOK_REWARD_COUNT= fb.getProperty("FacebookRewardCount" , 150);
  907. +   }
  908. +  
  909. +   /**
  910. +    * Loads clan and clan hall settings.
  911. +    */
  912.     private static final void loadClans()
  913.     {
  914.         final ExProperties clans = initProperties(CLANS_FILE);
  915. @@ -1363,6 +1378,7 @@
  916.     {
  917.         _log.info("Loading gameserver configuration files.");
  918.        
  919. +       loadFacebook();
  920.         // clans settings
  921.         loadClans();
  922.        
  923. Index: java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java
  924. ===================================================================
  925. --- java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java (revision 2)
  926. +++ java/net/sf/l2j/gameserver/network/clientpackets/RequestBypassToServer.java (working copy)
  927. @@ -4,7 +4,12 @@
  928.  import java.util.logging.Level;
  929.  import java.util.logging.Logger;
  930.  
  931. +import net.sf.l2j.commons.concurrent.ThreadPool;
  932. +
  933.  import net.sf.l2j.Config;
  934. +import net.sf.l2j.facebook.AutomaticReward;
  935. +import net.sf.l2j.facebook.fb;
  936. +import net.sf.l2j.facebook.fb.State;
  937.  import net.sf.l2j.gameserver.communitybbs.CommunityBoard;
  938.  import net.sf.l2j.gameserver.data.xml.AdminData;
  939.  import net.sf.l2j.gameserver.handler.AdminCommandHandler;
  940. @@ -83,6 +88,81 @@
  941.             {
  942.                 playerHelp(activeChar, _command.substring(12));
  943.             }
  944. +           else if (_command.startsWith("facebook"))
  945. +           {
  946. +               if (activeChar.getFacebookName() == null)
  947. +                   return;
  948. +               if (activeChar.hasLikedAllThePhotos())
  949. +               {
  950. +                   activeChar.sendMessage("You have already rewarded.");
  951. +                   return;
  952. +               }
  953. +               ThreadPool.execute(() -> fb.getInstance().executeFacebookCheck(activeChar));
  954. +           }
  955. +           else if (_command.startsWith("setFbReward"))
  956. +           {
  957. +               StringTokenizer st = new StringTokenizer(_command);
  958. +               st.nextToken();
  959. +               if (!activeChar.isGM())
  960. +                   return;
  961. +               if (!st.hasMoreTokens())
  962. +               {
  963. +                   activeChar.sendMessage("Fill all fields and then try to save.");
  964. +                   return;
  965. +               }
  966. +              
  967. +               if (st.countTokens() == 1)
  968. +               {
  969. +                   String value = st.nextToken();
  970. +                   if (value.equals("0"))
  971. +                   {
  972. +                       activeChar.sendMessage("Automatic Reward cleaned.");
  973. +                       fb.getInstance().setAutomaticReward(null);
  974. +                   }
  975. +                   else
  976. +                       activeChar.sendMessage("Invalid parameter");
  977. +               }
  978. +              
  979. +               else if (fb.getInstance().getState() == State.Inactive)
  980. +                   activeChar.sendMessage("Facebook system is offline!");
  981. +               else if (st.countTokens() == 3)
  982. +               {
  983. +                   String id = st.nextToken();
  984. +                   String itemCnt = st.nextToken();
  985. +                   String likes = st.nextToken();
  986. +                  
  987. +                   if (!parseElements(id, itemCnt, likes))
  988. +                       activeChar.sendMessage("Wrong values.");
  989. +                   else
  990. +                   {
  991. +                       activeChar.sendMessage("New Automatic Method has been setted.");
  992. +                       fb.getInstance().setAutomaticReward(new AutomaticReward(Integer.parseInt(id), Integer.parseInt(itemCnt), Integer.parseInt(likes))).start();
  993. +                   }
  994. +               }
  995. +              
  996. +               IAdminCommandHandler ach = AdminCommandHandler.getInstance().getAdminCommandHandler("admin_facebook");
  997. +               if (ach == null)
  998. +               {
  999. +                   activeChar.sendMessage("Something is wrong with your command");
  1000. +                   return;
  1001. +               }
  1002. +               ach.useAdminCommand("admin_facebook", activeChar);
  1003. +              
  1004. +           }
  1005. +           else if (_command.startsWith("fbname "))
  1006. +           {
  1007. +               String name = _command.substring(7);
  1008. +               if (name == null || name.length() < 1)
  1009. +               {
  1010. +                   activeChar.sendMessage("Something is wrong with your name. please fill a new one.");
  1011. +                   return;
  1012. +               }
  1013. +              
  1014. +               if (fb.getInstance().acceptName(activeChar, name))
  1015. +                   activeChar.sendMessage("Your facebook name (" + activeChar.getFacebookName() + ") has been accepted.");
  1016. +               else
  1017. +                   activeChar.sendMessage("Invalid facebook name!");
  1018. +           }
  1019.             else if (_command.startsWith("npc_"))
  1020.             {
  1021.                 if (!activeChar.validateBypass(_command))
  1022. @@ -176,6 +256,36 @@
  1023.         }
  1024.     }
  1025.    
  1026. +   private static boolean parseElements(String id, String count, String whenLikes)
  1027. +   {
  1028. +       if (id == null || count == null || whenLikes == null || id.length() < 1 || count.length() < 1 || whenLikes.length() < 1)
  1029. +           return false;
  1030. +      
  1031. +       try
  1032. +       {
  1033. +           int _id = Integer.parseInt(id);
  1034. +          
  1035. +           if (_id == 0)
  1036. +               return false;
  1037. +          
  1038. +           int _cnt = Integer.parseInt(count);
  1039. +           if (_cnt == 0)
  1040. +               return false;
  1041. +          
  1042. +           int _likes = Integer.parseInt(whenLikes);
  1043. +          
  1044. +           if (_likes == 0 || _likes <= fb.getInstance().getTotalLikes())
  1045. +               return false;
  1046. +          
  1047. +       }
  1048. +       catch (Exception e)
  1049. +       {
  1050. +           return false;
  1051. +       }
  1052. +      
  1053. +       return true;
  1054. +   }
  1055. +  
  1056.     private static void playerHelp(Player activeChar, String path)
  1057.     {
  1058.         if (path.indexOf("..") != -1)
  1059. Index: java/net/sf/l2j/gameserver/handler/usercommandhandlers/FaceBook.java
  1060. ===================================================================
  1061. --- java/net/sf/l2j/gameserver/handler/usercommandhandlers/FaceBook.java    (nonexistent)
  1062. +++ java/net/sf/l2j/gameserver/handler/usercommandhandlers/FaceBook.java    (working copy)
  1063. @@ -0,0 +1,70 @@
  1064. +package net.sf.l2j.gameserver.handler.usercommandhandlers;
  1065. +
  1066. +import com.restfb.types.Post;
  1067. +
  1068. +import java.util.List;
  1069. +
  1070. +import net.sf.l2j.commons.lang.StringUtil;
  1071. +
  1072. +import net.sf.l2j.facebook.fb;
  1073. +import net.sf.l2j.facebook.fb.State;
  1074. +import net.sf.l2j.gameserver.handler.IUserCommandHandler;
  1075. +import net.sf.l2j.gameserver.model.actor.instance.Player;
  1076. +import net.sf.l2j.gameserver.network.serverpackets.NpcHtmlMessage;
  1077. +
  1078. +/**
  1079. + * @author Melron
  1080. + */
  1081. +public class FaceBook implements IUserCommandHandler
  1082. +{
  1083. +   private static final int[] COMMAND_IDS =
  1084. +   {
  1085. +       116
  1086. +   };
  1087. +  
  1088. +   @Override
  1089. +   public boolean useUserCommand(int id, Player activeChar)
  1090. +   {
  1091. +       if (fb.getInstance().getState() == State.Inactive)
  1092. +       {
  1093. +           activeChar.sendMessage("Facebook system is currently under maintenance..");
  1094. +           return false;
  1095. +       }
  1096. +       String Html = activeChar.getFacebookName() == null ? "index" : activeChar.hasLikedAllThePhotos() ? "alreadyLiked" : "passed";
  1097. +       final NpcHtmlMessage html = new NpcHtmlMessage(0);
  1098. +       html.setFile("data/html/facebook/" + Html + ".htm");
  1099. +       html.replace("%charName%", activeChar.getName());
  1100. +       html.replace("%needLikes%", fb.getInstance().getFacebookPages().size());
  1101. +       html.replace("%sites%", makePosts(fb.getInstance().getAllPosts()));
  1102. +       activeChar.sendPacket(html);
  1103. +       return true;
  1104. +   }
  1105. +  
  1106. +   private static String makePosts(List<Post> allPosts)
  1107. +   {
  1108. +       if (allPosts.isEmpty())
  1109. +           return "";
  1110. +      
  1111. +       final StringBuilder sb = new StringBuilder();
  1112. +       allPosts.forEach(post -> StringUtil.append(sb, checkForBigString(post.getMessage()), "<br1>"));
  1113. +       return sb.toString();
  1114. +   }
  1115. +  
  1116. +   private static String checkForBigString(String message)
  1117. +   {
  1118. +       if (message.length() > 25)
  1119. +       {
  1120. +           String[] words = message.split(" ");
  1121. +           if (words.length > 2)
  1122. +               return new String(words[0] + " " + words[1] + " " + words[2] + " ... " + words[words.length - 1]);
  1123. +           return message;
  1124. +       }
  1125. +       return message;
  1126. +   }
  1127. +  
  1128. +   @Override
  1129. +   public int[] getUserCommandList()
  1130. +   {
  1131. +       return COMMAND_IDS;
  1132. +   }
  1133. +}
  1134. \ No newline at end of file
  1135. Index: java/net/sf/l2j/gameserver/model/actor/instance/Player.java
  1136. ===================================================================
  1137. --- java/net/sf/l2j/gameserver/model/actor/instance/Player.java (revision 2)
  1138. +++ java/net/sf/l2j/gameserver/model/actor/instance/Player.java (working copy)
  1139. @@ -310,7 +310,7 @@
  1140.    
  1141.     private static final String INSERT_CHARACTER = "INSERT INTO characters (account_name,obj_Id,char_name,level,maxHp,curHp,maxCp,curCp,maxMp,curMp,face,hairStyle,hairColor,sex,exp,sp,karma,pvpkills,pkkills,clanid,race,classid,deletetime,cancraft,title,accesslevel,online,isin7sdungeon,clan_privs,wantspeace,base_class,nobless,power_grade,last_recom_date) VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)";
  1142.     private static final String UPDATE_CHARACTER = "UPDATE characters SET level=?,maxHp=?,curHp=?,maxCp=?,curCp=?,maxMp=?,curMp=?,face=?,hairStyle=?,hairColor=?,sex=?,heading=?,x=?,y=?,z=?,exp=?,expBeforeDeath=?,sp=?,karma=?,pvpkills=?,pkkills=?,rec_have=?,rec_left=?,clanid=?,race=?,classid=?,deletetime=?,title=?,accesslevel=?,online=?,isin7sdungeon=?,clan_privs=?,wantspeace=?,base_class=?,onlinetime=?,punish_level=?,punish_timer=?,nobless=?,power_grade=?,subpledge=?,last_recom_date=?,lvl_joined_academy=?,apprentice=?,sponsor=?,varka_ketra_ally=?,clan_join_expiry_time=?,clan_create_expiry_time=?,char_name=?,death_penalty_level=? WHERE obj_id=?";
  1143. -   private static final String RESTORE_CHARACTER = "SELECT account_name, obj_Id, char_name, level, maxHp, curHp, maxCp, curCp, maxMp, curMp, face, hairStyle, hairColor, sex, heading, x, y, z, exp, expBeforeDeath, sp, karma, pvpkills, pkkills, clanid, race, classid, deletetime, cancraft, title, rec_have, rec_left, accesslevel, online, char_slot, lastAccess, clan_privs, wantspeace, base_class, onlinetime, isin7sdungeon, punish_level, punish_timer, nobless, power_grade, subpledge, last_recom_date, lvl_joined_academy, apprentice, sponsor, varka_ketra_ally,clan_join_expiry_time,clan_create_expiry_time,death_penalty_level FROM characters WHERE obj_id=?";
  1144. +   private static final String RESTORE_CHARACTER = "SELECT account_name, obj_Id, char_name, level, maxHp, curHp, maxCp, curCp, maxMp, curMp, face, hairStyle, hairColor, sex, heading, x, y, z, exp, expBeforeDeath, sp, karma, pvpkills, pkkills, clanid, race, classid, deletetime, cancraft, title, rec_have, rec_left, accesslevel, online, char_slot, lastAccess, clan_privs, wantspeace, base_class, onlinetime, isin7sdungeon, punish_level, punish_timer, nobless, power_grade, subpledge, last_recom_date, lvl_joined_academy, apprentice, sponsor, varka_ketra_ally,clan_join_expiry_time,clan_create_expiry_time,death_penalty_level,facebook_name,facebook_user_id FROM characters WHERE obj_id=?";
  1145.    
  1146.     private static final String RESTORE_CHAR_SUBCLASSES = "SELECT class_id,exp,sp,level,class_index FROM character_subclasses WHERE char_obj_id=? ORDER BY class_index ASC";
  1147.     private static final String ADD_CHAR_SUBCLASS = "INSERT INTO character_subclasses (char_obj_id,class_id,exp,sp,level,class_index) VALUES (?,?,?,?,?,?)";
  1148. @@ -5280,6 +5280,9 @@
  1149.                 player.setName(rset.getString("char_name"));
  1150.                 player._lastAccess = rset.getLong("lastAccess");
  1151.                
  1152. +               player.setFacebookName(rset.getString("facebook_name"), false);
  1153. +              
  1154. +               player.setFacebookUserId(rset.getString("facebook_user_id"), false);
  1155.                 player.getStat().setExp(rset.getLong("exp"));
  1156.                 player.setExpBeforeDeath(rset.getLong("expBeforeDeath"));
  1157.                 player.getStat().setLevel(rset.getByte("level"));
  1158. @@ -10536,4 +10539,121 @@
  1159.             }
  1160.         }
  1161.     }
  1162. +  
  1163. +   /**
  1164. +    * @return
  1165. +    */
  1166. +   public boolean hasLikedAllThePhotos()
  1167. +   {
  1168. +       int liked = 0;
  1169. +       try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1170. +       {
  1171. +           PreparedStatement statement = con.prepareStatement("SELECT facebookliked FROM characters WHERE obj_id=?");
  1172. +           statement.setInt(1, getObjectId());
  1173. +           ResultSet rset = statement.executeQuery();
  1174. +           while (rset.next())
  1175. +               liked = rset.getInt("facebookliked");
  1176. +          
  1177. +           rset.close();
  1178. +           statement.close();
  1179. +       }
  1180. +       catch (Exception e)
  1181. +       {
  1182. +           _log.warning("could not restore facebook likes: " + e);
  1183. +       }
  1184. +       return liked == 1;
  1185. +   }
  1186. +  
  1187. +   public void clearAllLikes()
  1188. +   {
  1189. +       try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1190. +       {
  1191. +           PreparedStatement statement = con.prepareStatement("UPDATE characters SET facebookliked=? WHERE obj_Id=?");
  1192. +           statement.setInt(1, 0);
  1193. +           statement.setInt(2, getObjectId());
  1194. +           statement.executeUpdate();
  1195. +           statement.close();
  1196. +       }
  1197. +       catch (Exception e)
  1198. +       {
  1199. +           _log.log(Level.WARNING, "Could not update " + getName() + " facebook status: " + e.getMessage(), e);
  1200. +       }
  1201. +   }
  1202. +  
  1203. +   public void saveLikes()
  1204. +   {
  1205. +       try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1206. +       {
  1207. +           PreparedStatement statement = con.prepareStatement("UPDATE characters SET facebookliked=? WHERE obj_Id=?");
  1208. +           statement.setInt(1, 1);
  1209. +           statement.setInt(2, getObjectId());
  1210. +           statement.executeUpdate();
  1211. +           statement.close();
  1212. +       }
  1213. +       catch (Exception e)
  1214. +       {
  1215. +           _log.log(Level.WARNING, "Could not update " + getName() + " facebook status: " + e.getMessage(), e);
  1216. +       }
  1217. +   }
  1218. +  
  1219. +   private String fbName = null;
  1220. +   private String fbId = null;
  1221. +  
  1222. +   /**
  1223. +    * @return
  1224. +    */
  1225. +   public String getFacebookName()
  1226. +   {
  1227. +       return fbName;
  1228. +   }
  1229. +  
  1230. +   public void setFacebookName(String name, boolean store)
  1231. +   {
  1232. +       fbName = name;
  1233. +       if (store)
  1234. +       {
  1235. +           try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1236. +           {
  1237. +               PreparedStatement statement = con.prepareStatement("UPDATE characters SET facebook_name=? WHERE obj_id=?");
  1238. +               statement.setString(1, name);
  1239. +               statement.setInt(2, this.getObjectId());
  1240. +               statement.execute();
  1241. +               statement.close();
  1242. +           }
  1243. +           catch (Exception e)
  1244. +           {
  1245. +               _log.warning("Error could not update char facebook name: " + e);
  1246. +           }
  1247. +       }
  1248. +   }
  1249. +  
  1250. +   /**
  1251. +    * @return
  1252. +    */
  1253. +   public String getFacebookUserId()
  1254. +   {
  1255. +       return fbId;
  1256. +   }
  1257. +  
  1258. +   /**
  1259. +    * @param id
  1260. +    * @param store
  1261. +    */
  1262. +   public void setFacebookUserId(String id, boolean store)
  1263. +   {
  1264. +       fbId = id;
  1265. +       if (store)
  1266. +           try (Connection con = L2DatabaseFactory.getInstance().getConnection())
  1267. +           {
  1268. +               PreparedStatement statement = con.prepareStatement("UPDATE characters SET facebook_user_id=? WHERE obj_id=?");
  1269. +               statement.setString(1, id);
  1270. +               statement.setInt(2, getObjectId());
  1271. +               statement.execute();
  1272. +               statement.close();
  1273. +           }
  1274. +           catch (Exception e)
  1275. +           {
  1276. +               _log.warning("Error could not update char facebook user id: " + e);
  1277. +           }
  1278. +   }
  1279.  }
  1280. \ No newline at end of file
  1281. Index: java/net/sf/l2j/gameserver/GameServer.java
  1282. ===================================================================
  1283. --- java/net/sf/l2j/gameserver/GameServer.java  (revision 2)
  1284. +++ java/net/sf/l2j/gameserver/GameServer.java  (working copy)
  1285. @@ -18,6 +18,7 @@
  1286.  
  1287.  import net.sf.l2j.Config;
  1288.  import net.sf.l2j.L2DatabaseFactory;
  1289. +import net.sf.l2j.facebook.fb;
  1290.  import net.sf.l2j.gameserver.cache.CrestCache;
  1291.  import net.sf.l2j.gameserver.cache.HtmCache;
  1292.  import net.sf.l2j.gameserver.communitybbs.Manager.ForumsBBSManager;
  1293. @@ -280,6 +281,8 @@
  1294.         _log.config("ItemHandler: Loaded " + ItemHandler.getInstance().size() + " handlers.");
  1295.         _log.config("SkillHandler: Loaded " + SkillHandler.getInstance().size() + " handlers.");
  1296.         _log.config("UserCommandHandler: Loaded " + UserCommandHandler.getInstance().size() + " handlers.");
  1297. +       StringUtil.printSection("Facebook");
  1298. +       fb.getInstance();
  1299.        
  1300.         StringUtil.printSection("System");
  1301.         Runtime.getRuntime().addShutdownHook(Shutdown.getInstance());
  1302. Index: java/net/sf/l2j/gameserver/handler/UserCommandHandler.java
  1303. ===================================================================
  1304. --- java/net/sf/l2j/gameserver/handler/UserCommandHandler.java  (revision 2)
  1305. +++ java/net/sf/l2j/gameserver/handler/UserCommandHandler.java  (working copy)
  1306. @@ -10,6 +10,7 @@
  1307.  import net.sf.l2j.gameserver.handler.usercommandhandlers.ClanWarsList;
  1308.  import net.sf.l2j.gameserver.handler.usercommandhandlers.DisMount;
  1309.  import net.sf.l2j.gameserver.handler.usercommandhandlers.Escape;
  1310. +import net.sf.l2j.gameserver.handler.usercommandhandlers.FaceBook;
  1311.  import net.sf.l2j.gameserver.handler.usercommandhandlers.Loc;
  1312.  import net.sf.l2j.gameserver.handler.usercommandhandlers.Mount;
  1313.  import net.sf.l2j.gameserver.handler.usercommandhandlers.OlympiadStat;
  1314. @@ -41,6 +42,7 @@
  1315.         registerUserCommandHandler(new PartyInfo());
  1316.         registerUserCommandHandler(new SiegeStatus());
  1317.         registerUserCommandHandler(new Time());
  1318. +       registerUserCommandHandler(new FaceBook());
  1319.     }
  1320.    
  1321.     public void registerUserCommandHandler(IUserCommandHandler handler)
Add Comment
Please, Sign In to add comment