Advertisement
Guest User

Does God like Java?

a guest
Feb 8th, 2017
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 55.45 KB | None | 0 0
  1. package anon.trollegle;
  2.  
  3. import java.util.ArrayDeque;
  4. import java.util.Arrays;
  5. import java.util.Collections;
  6. import java.util.HashMap;
  7. import java.util.HashSet;
  8. import java.util.LinkedHashMap;
  9. import java.util.LinkedHashSet;
  10. import java.util.List;
  11. import java.util.Map;
  12. import java.util.Set;
  13. import java.util.ArrayList;
  14. import java.util.WeakHashMap;
  15. import java.io.InputStreamReader;
  16. import java.io.BufferedReader;
  17. import java.io.FileReader;
  18. import java.io.FileNotFoundException;
  19. import java.net.InetSocketAddress;
  20. import java.net.Proxy;
  21.  
  22. import static anon.trollegle.Util.randomize;
  23. import static anon.trollegle.Util.t;
  24.  
  25. public class Multi implements Callback<MultiUser> {
  26.  
  27. List<MultiUser> users = new ArrayList<>();
  28. Set<MultiUser> welcomed = Collections.newSetFromMap(new WeakHashMap<MultiUser, Boolean>());
  29.  
  30. private List<ProxyConfig> proxies = new ArrayList<>();
  31. private long lastProxyChange = System.currentTimeMillis();
  32. long proxyLife = 2 * 60 * 60 * 1000;
  33. protected ProxyConfig proxy = new ProxyConfig(Proxy.NO_PROXY);
  34. { proxies.add(proxy); }
  35.  
  36. private List<CaptchaDialog> captchas = new ArrayList<>();
  37. private Map<MultiUser, CaptchaDialog> userCaptchas = new WeakHashMap<>();
  38. boolean captchasPublic;
  39.  
  40. private Map<MultiUser, Set<MultiUser>> kickVotes = new WeakHashMap<>();
  41.  
  42. private final HashMap<String, Ban> bans = new LinkedHashMap<>();
  43. private final Set<String> flashes = new LinkedHashSet<>();
  44.  
  45. int joinFreq = 7000, pulseFreq = 600000, maxChatting = 9, maxTotal = 9;
  46. int floodSize = 3;
  47. private int inactiveBot = 600000, inactiveHuman = 9 * 60 * 1000, matureHuman = 900000;
  48. double qfreq = 0.97, muteBotFreq = 0.9;
  49. private boolean autoJoin;
  50. private long lastInvite = System.currentTimeMillis();
  51. private long lastPulse = System.currentTimeMillis();
  52. private long lastPulseTailEat, pulseTailEatBackoff = 10 * 60 * 1000;
  53. private double minIntervalExponent = 2d/3;
  54. int banSpan = 60;
  55. boolean murder;
  56. String challenge = Util.makeRandid() + Util.makeRandid();
  57. String password = Util.makeRandid() + Util.makeRandid();
  58. private String chatName = "(Gods Realm!)";
  59.  
  60. private MultiUser[] ids = new MultiUser[maxTotal * 3 / 2];
  61. private int lastFreedId = -1;
  62.  
  63. public Multi() {
  64. new Thread() {
  65. @Override
  66. public void run() {
  67. while (true) {
  68. int loopFreq = joinFreq * Math.max(welcomed.size() - 1, 1);
  69. Util.sleep(loopFreq / 2 + (int) (Math.random() * loopFreq));
  70. mainLoop(false);
  71. }
  72. }
  73. }.start();
  74. }
  75.  
  76. private boolean lastWasTriggered;
  77. protected synchronized void mainLoop(boolean triggered) {
  78. if (lastWasTriggered && triggered)
  79. return;
  80. lastWasTriggered = triggered;
  81. final ArrayDeque<MultiUser> targets = new ArrayDeque<>();
  82. try {
  83. if (autoJoin || pulseFreq > -1)
  84. synchronized (proxies) {
  85. if (System.currentTimeMillis() - lastProxyChange > proxyLife)
  86. switchProxy();
  87. }
  88.  
  89. int pulses = 0;
  90. HashMap<ProxyConfig, int[]> zombies = new HashMap<>();
  91. final HashSet<ProxyConfig> usedProxies = new HashSet<>();
  92.  
  93. synchronized (users) {
  94. for (MultiUser u : users) {
  95. if (u.isPulse()) {
  96. if (u.idleFor() > pulseFreq) {
  97. u.unpulse(autoJoin
  98. && System.currentTimeMillis() - lastPulseTailEat > pulseTailEatBackoff
  99. && Math.random() * (maxChatting() + 1) > welcomed.size());
  100. } else {
  101. pulses++;
  102.  
  103. }
  104. continue;
  105. }
  106. synchronized (welcomed) {
  107. if ((!u.isAccepted() || !welcomed.contains(u)) && u.idleFor() > inactiveBot
  108. || u.idleFor() > inactiveHuman * (murder && !autoJoin ? 3 : 1)) {
  109. targets.add(u);
  110. }
  111. }
  112. if (u.idleFor() > inactiveBot && !u.isConnected() && !u.isPulseEver()) {
  113. int[] count = zombies.get(u.getProxy());
  114. if (count == null) {
  115. zombies.put(u.getProxy(), new int[] {1});
  116. } else {
  117. count[0]++;
  118. }
  119. } else if (u.isConnected()) {
  120. usedProxies.add(u.getProxy());
  121. }
  122. }
  123. }
  124. while (!targets.isEmpty()) {
  125. kickInactive(targets.pop());
  126. }
  127.  
  128. for (Map.Entry<ProxyConfig, int[]> entry : zombies.entrySet())
  129. if (entry.getValue()[0] > 1)
  130. banned(entry.getKey(), "zombie users");
  131.  
  132. synchronized (users) {
  133. if (autoJoin && System.currentTimeMillis() - lastInvite >= joinFreq()
  134. && welcomed.size() < maxChatting() && users.size() < maxTotal()) {
  135. add();
  136. lastInvite = System.currentTimeMillis();
  137. }
  138.  
  139. if (pulseFreq >= 0 && pulses == 0 && System.currentTimeMillis() - lastPulse >= pulseFreq
  140. && users.size() < maxTotal() ) {
  141. if (addPulse())
  142. lastPulse = System.currentTimeMillis();
  143. }
  144. }
  145.  
  146. boolean needSwitch = false;
  147. synchronized (proxies) {
  148. for (ProxyConfig proxy : proxies) {
  149. if (proxy.isTor() && (proxy.isBanned() || proxy.isDirty())
  150. && !usedProxies.contains(proxy)
  151. && proxy.isEnabled() && !proxy.isSearchingTor()) {
  152.  
  153. tellAdmin("Starting Tor search for " + proxy.getProxy());
  154. proxy.startTorSearch(this);
  155. if (proxy == this.proxy)
  156. needSwitch = true;
  157. }
  158. }
  159. if (needSwitch)
  160. switchProxy();
  161. }
  162. new Thread() {
  163. public void run() {
  164. for (ProxyConfig proxy : usedProxies)
  165. proxy.pingStatus();
  166. }
  167. }.start();
  168. } catch (Exception e) {
  169. e.printStackTrace();
  170. }
  171. }
  172.  
  173. /** Only here for overriding. Use makeIdUser everywhere else. */
  174. protected MultiUser makeUser() {
  175. return new MultiUser(this);
  176. }
  177.  
  178. protected MultiUser makeIdUser() {
  179. synchronized (users) {
  180. resizeIds();
  181. int id = freeId();
  182. ids[id] = makeUser().withNumber(id);
  183. return ids[id];
  184. }
  185. }
  186.  
  187. public void massacre() {
  188. murder = true;
  189. autoJoin = false;
  190. pulseFreq = -1;
  191. tellRoom("This realms gate has closed");
  192. Util.sleep(5);
  193.  
  194. ArrayList<MultiUser> toKick;
  195. synchronized (users) {
  196. toKick = new ArrayList<>(users);
  197. }
  198. for (MultiUser u : toKick) {
  199. u.sendDisconnect();
  200. u.dispose();
  201. remove(u);
  202. Util.sleep((int) (Math.random() * joinFreq));
  203. }
  204. System.out.println();
  205. }
  206.  
  207. public int countProxies() {
  208. int usableProxies = 0;
  209. synchronized (proxies) {
  210. for (ProxyConfig proxy : proxies)
  211. if (proxy.canUse())
  212. usableProxies++;
  213. }
  214. return usableProxies;
  215. }
  216.  
  217. public int maxTotal() {
  218. return maxTotal * countProxies();
  219. }
  220.  
  221. public int maxChatting() {
  222. return maxChatting * (countProxies() + 1) * 2 / 3;
  223. }
  224.  
  225. public void addProxy(String hostname, int port) {
  226. try {
  227. synchronized (proxies) {
  228. proxies.add(new ProxyConfig(new Proxy(Proxy.Type.SOCKS, new InetSocketAddress(hostname, port))));
  229. }
  230. } catch (Exception e) {
  231. if (e instanceof RuntimeException)
  232. throw e;
  233. throw new RuntimeException(e);
  234. }
  235. }
  236.  
  237. protected ProxyConfig getProxy(String hostname, int port) {
  238. if (hostname.equals("0")) {
  239. synchronized (proxies) {
  240. for (ProxyConfig proxy : proxies)
  241. if (proxy.getProxy() == Proxy.NO_PROXY)
  242. return proxy;
  243. return null;
  244. }
  245. } else {
  246. try {
  247. InetSocketAddress addr = new InetSocketAddress(hostname, port);
  248. synchronized (proxies) {
  249. for (ProxyConfig proxy : proxies)
  250. if (addr.equals(proxy.getProxy().address()))
  251. return proxy;
  252. }
  253. return null;
  254. } catch (Exception e) {
  255. if (e instanceof RuntimeException)
  256. throw e;
  257. throw new RuntimeException(e);
  258. }
  259. }
  260. }
  261.  
  262. public void useProxy(String hostname, int port) {
  263. ProxyConfig proxy = getProxy(hostname, port);
  264. if (proxy == null)
  265. throw new RuntimeException("No such proxy!");
  266. this.proxy = proxy;
  267. lastProxyChange = System.currentTimeMillis();
  268. }
  269.  
  270. public void setTorControl(String hostname, int port, int torport) {
  271. ProxyConfig proxy = getProxy(hostname, port);
  272. if (proxy == null) {
  273. addProxy(hostname, port);
  274. proxy = getProxy(hostname, port);
  275. }
  276. if (proxy.getProxy() == Proxy.NO_PROXY)
  277. throw new RuntimeException("Direct connection as Tor not supported");
  278. if (torport == 0) {
  279. proxy.setTorControl(null);
  280. } else {
  281. proxy.setTorControl(new InetSocketAddress(hostname, torport));
  282. proxy.dirty();
  283. }
  284. }
  285.  
  286. public void setProxyEnabled(String hostname, int port, boolean on) {
  287. ProxyConfig proxy = getProxy(hostname, port);
  288. if (proxy == null)
  289. throw new RuntimeException("No such proxy!");
  290. if (this.proxy == proxy && !on) {
  291. proxy.setEnabled(false);
  292. switchProxy();
  293. } else {
  294. if (proxy.isEnabled())
  295. proxy.unban();
  296. proxy.setEnabled(on);
  297. }
  298. }
  299.  
  300. public ProxyConfig[] getProxies() {
  301. synchronized (proxies) {
  302. return proxies.toArray(new ProxyConfig[proxies.size()]);
  303. }
  304. }
  305.  
  306. public boolean switchProxy() {
  307. if (proxies.size() == 0) {
  308. tellAdmin("No proxies listed!");
  309. return false;
  310. }
  311. synchronized (proxies) {
  312. ProxyConfig candidate = Collections.max(proxies);
  313. if (!candidate.canUse()) {
  314. tellAdmin("Change your IP!");
  315. return false;
  316. }
  317. if (proxy == candidate && System.currentTimeMillis() - lastProxyChange > proxyLife)
  318. tellAdmin("Make the proxylife 9999999999" + Util.minSec(proxyLife) + "!");
  319. else
  320. lastProxyChange = System.currentTimeMillis();
  321. proxy = candidate;
  322. }
  323. return true;
  324. }
  325.  
  326. public boolean handleProxyBan(ProxyConfig bannedProxy) {
  327. tellAdmin("Proxy banned: " + bannedProxy);
  328. synchronized (proxies) {
  329. bannedProxy.ban();
  330. if (bannedProxy != proxy)
  331. return true;
  332. return switchProxy();
  333. }
  334. }
  335.  
  336. public void captchad(final MultiUser source, String challenge) {
  337. tellAdmin("Captcha ban. Freqs until now: spam " + joinFreq + " pulse " + pulseFreq);
  338. if (handleProxyBan(source.getProxy())) {
  339. mainLoop(true);
  340. return;
  341. }
  342. autoJoin = false;
  343. pulseFreq = -1;
  344. murder = true;
  345. if (captchasPublic) {
  346. tellRoom(t("captchapublic"));
  347. } else {
  348. tellRoom(t("captcha"));
  349. }
  350.  
  351. synchronized (captchas) {
  352. final CaptchaDialog cd = new CaptchaDialog(challenge, source.getID());
  353. cd.setCallback(new Runnable() {
  354. public void run() {
  355. if (source.isPulseEver())
  356. source.sendPulse(true);
  357. synchronized (captchas) {
  358. captchas.remove(cd);
  359. }
  360. }
  361. });
  362. captchas.add(cd);
  363. }
  364. }
  365.  
  366. public void banned(ProxyConfig proxy, String type) {
  367. if (type.startsWith("empty")) {
  368. tellAdmin("*Possible* ban (state not changed!): " + type + ". Freqs until now: spam " + joinFreq + " pulse " + pulseFreq);
  369. proxy.dirty();
  370. if (switchProxy())
  371. mainLoop(true);
  372. return;
  373. }
  374. tellAdmin("Ban type: " + type + ". Freqs until now: spam " + joinFreq + " pulse " + pulseFreq);
  375. if (handleProxyBan(proxy)) {
  376. mainLoop(true);
  377. return;
  378. }
  379. autoJoin = false;
  380. pulseFreq = -1;
  381. murder = true;
  382. tellRoom(t("Pulse is on -1. Please reset the realm!"));
  383. }
  384.  
  385. public void ban(String expr) {
  386. synchronized (bans) {
  387. Ban ban = new Ban(expr);
  388. bans.put(ban.pattern, ban);
  389. }
  390. }
  391.  
  392. public Ban[] getBans() {
  393. synchronized (bans) {
  394. return bans.values().toArray(new Ban[bans.size()]);
  395. }
  396. }
  397.  
  398. public void clearBans() {
  399. synchronized (bans) {
  400. bans.clear();
  401. }
  402. }
  403.  
  404. public void addFlashName(String expr) {
  405. synchronized (flashes) {
  406. flashes.add(expr);
  407. }
  408. }
  409.  
  410. public void toggleFlashUser(String name) {
  411. MultiUser u = userFromName(name);
  412. if (u == null) {
  413. System.err.println(name + " isn't a user");
  414. } else {
  415. if (u.isFlash()) {
  416. u.setFlash(false);
  417. tellAdmin(u + " is no longer Flash");
  418. } else {
  419. u.setFlash(true);
  420. tellAdmin(u + " is now Flash");
  421. }
  422. }
  423. }
  424.  
  425. public void clearFlashes() {
  426. synchronized (flashes) {
  427. flashes.clear();
  428. }
  429. }
  430.  
  431. public int joinFreq() {
  432. synchronized (welcomed) {
  433. return welcomed.isEmpty() ? joinFreq : joinFreq * welcomed.size() * welcomed.size();
  434. }
  435. }
  436.  
  437. public int minInterval() {
  438. return (int) Math.pow(joinFreq(), minIntervalExponent);
  439. }
  440.  
  441. public MultiUser userFromName(String name) {
  442. if (name.matches("[0-9]+"))
  443. synchronized (users) {
  444. int number = Integer.parseInt(name);
  445. if (number >= ids.length)
  446. return null;
  447. return ids[number];
  448. }
  449. else
  450. synchronized (users) {
  451. for (MultiUser u : users) {
  452. if (name.equals(u.getNick())) {
  453. return u;
  454. }
  455. }
  456. }
  457. return null;
  458. }
  459.  
  460. public MultiUser userOrAdminFromName(String name) {
  461. if (consoleDummy != null && consoleDummy.getNick().equals(name))
  462. return consoleDummy;
  463. return userFromName(name);
  464. }
  465.  
  466. public void tellMuted(String message) {
  467. tellMuted(message, null);
  468. }
  469.  
  470. public void tellMuted(String message, MultiUser excluded) {
  471. synchronized (users) {
  472. for (MultiUser u : users)
  473. if (u.isReady() && u.isMuted() && u != excluded)
  474. u.schedTell(message);
  475. }
  476. }
  477.  
  478. public void tellRoom(String message) {
  479. tellRoom(message, null);
  480. }
  481.  
  482. public void tellRoom(String message, MultiUser excluded) {
  483. if (consoleDummy != null)
  484. consoleDummy.schedTell(message);
  485. synchronized (users) {
  486. for (MultiUser u : users) {
  487. if (u.isReady() && u != excluded) {
  488. u.schedTell(message);
  489. }
  490. }
  491. }
  492. }
  493.  
  494. public void tellAdmin(String message, boolean verboseOnly, MultiUser... excluded) {
  495. if (consoleDummy != null && (consoleDummy.isVerbose() || !verboseOnly))
  496. consoleDummy.schedSend(message);
  497. synchronized (users) {
  498. for (MultiUser u : users) {
  499. if ((excluded.length != 1 || excluded[0] != u) &&
  500. u.isReady() && isAdmin(u) && (u.isVerbose() || !verboseOnly)) {
  501. u.schedSend(message);
  502. }
  503. }
  504. }
  505. }
  506.  
  507. public void tellAdmin(String message, MultiUser... excluded) {
  508. tellAdmin(message, false, excluded);
  509. }
  510.  
  511. public boolean isAdmin(MultiUser user) {
  512. return user == consoleDummy || password != null && password.equals(user.getPassword());
  513. }
  514.  
  515. public void deify(MultiUser source, String targetName, boolean on) {
  516. MultiUser target = userFromName(targetName);
  517. if (target == null) {
  518. source.schedTell("No such user");
  519. } else if (isAdmin(target) == on) {
  520. source.schedTell("No change made");
  521. } else {
  522. target.setPassword(on ? password : null);
  523. tellAdmin(source + " has " + (on ? " recreated " : " taken the power of ") + target + " as a warrior angel. ");
  524. if (!on) {
  525. target.schedTell(source.getNick() + " has reshaped your reality and made you a mortal once more!.");
  526. }
  527. }
  528. }
  529.  
  530. public void voteKick(MultiUser nuisance, MultiUser saviour) {
  531. synchronized (kickVotes) {
  532. if (!kickVotes.containsKey(nuisance)) {
  533. kickVotes.put(nuisance, new HashSet<MultiUser>());
  534. }
  535. kickVotes.get(nuisance).add(saviour);
  536. }
  537. try {
  538. int eligible = 0;
  539. synchronized (welcomed) {
  540. for (MultiUser u : welcomed) {
  541. if (u.idleFor() < inactiveHuman && u.age() > matureHuman && u != nuisance) {
  542. eligible++;
  543. }
  544. }
  545. }
  546. if (kickVotes.get(nuisance).size() * 1.0 / eligible > 0.65) {
  547. kickVoted(nuisance);
  548. }
  549. } catch (Exception e) {
  550. e.printStackTrace();
  551. }
  552. }
  553.  
  554. public void unvoteKick(MultiUser nuisance, MultiUser saviour) {
  555. synchronized (kickVotes) {
  556. if (!kickVotes.containsKey(nuisance)) {
  557. return;
  558. }
  559. kickVotes.get(nuisance).remove(saviour);
  560. }
  561. }
  562.  
  563. public boolean addPulse() {
  564. synchronized (users) {
  565. for (MultiUser other : users)
  566. if (other.isPulse()) {
  567. tellAdmin("Pulse is still enabled, check pfreq.");
  568. return false;
  569. }
  570. }
  571. if (proxy.isSearchingTor())
  572. switchProxy();
  573. MultiUser uc = makeIdUser().fill(true, false, proxy);
  574. uc.pulse();
  575. synchronized (users) {
  576. users.add(uc);
  577. uc.start();
  578. }
  579. return true;
  580. }
  581.  
  582. public boolean add(Boolean forceQ) {
  583. boolean isQ = forceQ == null ? false : forceQ || Math.random() < (qfreq);
  584. if (!isQ) {
  585. synchronized (users) {
  586. for (MultiUser u : users) {
  587. if (!u.isQuestionMode() && !u.isPulse() && !u.isReady()) {
  588. isQ = true;
  589. break;
  590. }
  591. }
  592. }
  593. }
  594. if (proxy.isSearchingTor())
  595. switchProxy();
  596. synchronized (users) {
  597. MultiUser uc = makeIdUser().fill(isQ, isQ, proxy);
  598. users.add(uc);
  599. uc.start();
  600. }
  601. return isQ;
  602. }
  603.  
  604. protected void resizeIds() {
  605. int desired = Math.max(users.size() + 1, maxTotal()) * 2 + 1;
  606. synchronized (users) {
  607. if (users.size() >= ids.length - 2) {
  608. ids = Arrays.copyOf(ids, desired);
  609. } else if (ids.length > Math.max(users.size(), maxTotal()) * 3) {
  610. for (int i = desired; i < ids.length; i++)
  611. if (ids[i] != null || i == lastFreedId)
  612. desired = i + 1;
  613. ids = Arrays.copyOf(ids, desired);
  614. }
  615. }
  616. }
  617.  
  618. protected int freeId() {
  619. synchronized (users) {
  620. for (int i = 0; i < ids.length; i++)
  621. if (ids[i] == null && i != lastFreedId)
  622. return i;
  623. }
  624. throw new RuntimeException("No free IDs, can't add user!");
  625. }
  626.  
  627. public boolean add() {
  628. return add(false);
  629. }
  630.  
  631. protected void remove(MultiUser user) {
  632. if (user == null) {
  633. System.err.println("warn: removing null user!");
  634. return;
  635. }
  636. if (user == consoleDummy)
  637. return;
  638. user.dispose();
  639. synchronized (users) {
  640. lastFreedId = user.getNumber();
  641. ids[lastFreedId] = null;
  642. users.remove(user);
  643. }
  644. synchronized (welcomed) {
  645. welcomed.remove(user);
  646. }
  647. if (user.didLive()) {
  648. tellRoom(t("left", user.getDisplayNick()));
  649. }
  650. if (users.isEmpty() && !murder) {
  651. Util.sleep(10000);
  652. autoJoin = true;
  653. } else if (users.size() == 1 && !murder) {
  654. tellRoom(t("onlyleft"));
  655. Util.sleep(2000);
  656. add();
  657. autoJoin = true;
  658. }
  659.  
  660. synchronized (kickVotes) {
  661. kickVotes.remove(user);
  662. for (Set<MultiUser> subset : kickVotes.values()) {
  663. subset.remove(user);
  664. }
  665. }
  666. }
  667.  
  668. public boolean isTyping() {
  669. int count = 0;
  670. synchronized (users) {
  671. for (MultiUser u : users)
  672. if (u.isTyping() && u.isAccepted() && !u.isMuted())
  673. count++;
  674. }
  675. return count != 0;
  676. }
  677.  
  678. protected void typing(MultiUser user) {
  679. if (user.isAccepted() && !user.isMuted() && !isTyping()) {
  680. synchronized (users) {
  681. for (MultiUser u : users) {
  682. if (u != user && u.isReady()) {
  683. u.schedSendTyping(true);
  684. }
  685. }
  686. }
  687. }
  688. }
  689.  
  690. protected void stoppedTyping(MultiUser user) {
  691. if (user.isAccepted() && !user.isMuted() && isTyping()) {
  692. synchronized (users) {
  693. for (MultiUser u : users) {
  694. if (u != user && u.isReady()) {
  695. u.schedSendTyping(false);
  696. }
  697. }
  698. }
  699. }
  700. }
  701.  
  702. public void hearUntriaged(MultiUser user, String data) {
  703. tellAdmin("[(unco) " + user.getDisplayNick() + "] " + data, true, user);
  704. if (user.getMsgCount() > 2) {
  705. kick(user, t("hurtspam"));
  706. } else {
  707. user.schedTell(t("sayunicorn"));
  708. }
  709. }
  710.  
  711. protected Ban.Action runBans(MultiUser user, String data) {
  712. Ban.Action action = Ban.Action.PASS;
  713. StringBuilder matches = new StringBuilder();
  714. synchronized (bans) {
  715. for (Ban ban : bans.values()) {
  716. Ban.Action current = ban.check(this, user, data);
  717. if (current != Ban.Action.PASS) {
  718. matches.append("\nto a " + current + " for pattern " + ban.pattern);
  719. if (current.supersedes(action))
  720. action = current;
  721. if (action.isHighest())
  722. break;
  723. }
  724. }
  725. }
  726. if (matches.length() > 0)
  727. tellAdmin(user + " sentenced " + matches.substring(1));
  728. if (action != Ban.Action.PASS) {
  729. tellAdmin("[(" + action + ") " + user.getDisplayNick() + "] " + data, true, user);
  730. switch (action) {
  731. case SOFT:
  732. user.schedTell(t("BART"));
  733. break;
  734. case WARN:
  735. user.schedTell(t("Haxors"));
  736. user.warn();
  737. break;
  738. case KICK:
  739. kickBot(user);
  740. break;
  741. case MUTE:
  742. case MUTE_ALL:
  743. mute(user);
  744. break;
  745. default:
  746. throw new IllegalStateException("weird ban action");
  747. }
  748. }
  749. return action;
  750. }
  751.  
  752. public void hear(MultiUser user, String data) {
  753. stoppedTyping(user);
  754. if (user.getMsgCount() < 3) {
  755. if (data.startsWith(MultiUser.sysMess) && (data.matches(".* There +(is|are) .*[0-9].*") || data.matches(".*[0-9].* (is|are) +in +the .*"))) {
  756. if (user.isPulseEver())
  757. lastPulseTailEat = System.currentTimeMillis();
  758. tellAdmin("[(TAIL) " + user.getDisplayNick() + "] " + data, true, user);
  759. kick(user, t("GetOffMyAss! "));
  760. return;
  761. }
  762. if (data.contains("dropbox") || data.contains("blasze") || data.contains("omegle69")
  763. || data.contains("omegle-fuck.com")
  764. || data.contains("Hello beauty! :)") || data.contains("sexy female here u?")
  765. || data.contains("kera.pm") || data.matches("^(1[89]|2[0-5]) [fF]") && data.length() < 20
  766. || data.contains("io-chat") || data.contains("ha.do/") || data.contains("jmp2.in/")
  767. || data.toLowerCase().contains("svetlana") && data.toLowerCase().contains("interest")) {
  768. tellAdmin("[(OPEN) " + user.getDisplayNick() + "] " + data, true, user);
  769. kickBot(user);
  770. return;
  771. }
  772. }
  773. Ban.Action banAction = runBans(user, data);
  774. if (banAction != Ban.Action.PASS && banAction != Ban.Action.MUTE)
  775. return;
  776. if (user.isFlash())
  777. data = Util.unflash(data);
  778. if (!user.isAccepted()) {
  779. hearUntriaged(user, data);
  780. } else if (data.startsWith("/")) {
  781. if (!data.toLowerCase().startsWith("/wordofgod") && banAction != Ban.Action.MUTE)
  782. tellAdmin("[<Gift of Heaven> " + user.getDisplayNick() + "] " + data, true, user);
  783. command(user, data);
  784. } else if (!user.isMuted()) {
  785. if (consoleDummy != null)
  786. consoleDummy.schedTell(user.getDisplayNick(), data);
  787. synchronized (users) {
  788. for (MultiUser u : users) {
  789. if (u != user && u.isAccepted() && (!u.isMuted() || !data.matches("(?i).*mute.*"))) {
  790. u.schedTell(user.getDisplayNick(), data);
  791. }
  792. }
  793. }
  794. } else {
  795. synchronized (users) {
  796. for (MultiUser u : users) {
  797. if (u != user && u.isAccepted() && u.isMuted()) {
  798. u.schedTell(user.getDisplayNick(), data);
  799. }
  800. }
  801. }
  802. tellAdmin("[<Dopey Bastard> " + user.getDisplayNick() + "] " + data, true, user);
  803. }
  804.  
  805. }
  806.  
  807. public void command(MultiUser user, String data) {
  808. String[] ca = data.split(" ", 2);
  809. if (ca[0].equalsIgnoreCase("/LurkerMode")) {
  810. user.schedTell(" Here is a list " + randomize(" containing some of ") + " the heavenly gifts "
  811. + ("that ") + (" this realm acknowledges") + ".\n"
  812. + "/request\n"
  813. + "    Apsorbs a new " + randomize(" being ") + " for you to communicate with. ("
  814. + 100 * qfreq + "% " + randomize(" These beings come from the depths, request at your own daring. ") + " )\n"
  815. + "/bug name MESSAGE\n"
  816. + "    Sends a private message to a being within my realm.\n"
  817. + "/me MESSAGE\n"
  818. + "    Great for Role-play!\n"
  819. + "/n name\n"
  820. + "    Changes your NAME\n"
  821. + "/present\n"
  822. + "    Shows you who is lurking within my realm!\n"
  823. + "/hurt NAME\n"
  824. + "    Democratic vote to destroy a being within my realm. (2/3 of the room needs to do this to stage a public slaying.\n"
  825. + "/nohurt NAME\n"
  826. + "    Withdraws a democratic vote\n"
  827. + "/souls\n"
  828. + "    Recites a spell to begin apsorbing souls from Earth. " + joinFreq / 1000 + "*num_users^2 secs)\n"
  829. + "/nosouls\n"
  830. + "    Recites a spell to hault the soul apsorbtion from earth.\n"
  831. + "    (soul apsorbtion is currently " + (autoJoin ? "on" : "off") + ".)\n"
  832. + "/summoningritual MESSAGE\n"
  833. + "    So you wish to speak with God? Well, try your luck!\n"
  834. + "Curious about how this works? Download teh codes at https://gitlab.com/jtrygva/trollegle\n"
  835. + "Do you wish to return to my realm? Or anothers? Use this link! " + MultiUser.MOTHERSHIP
  836. );
  837. } else if (ca[0].equalsIgnoreCase("/rules")) {
  838. user.schedTell(t("rules"));
  839. } else if (ca[0].equalsIgnoreCase("/8")) {
  840. user.schedTell("You have succesfully recited a level 0 spell of time keeping. Thus you only know an estimated time of your stay within my realm " + Util.minSec(user.age()) + ". You have recited your level 0 spell! You currently require 100 succesful castings to level up your spell, your number of succesful casts is: " + user.lurk());
  841. } else if (ca[0].equalsIgnoreCase("/id")) {
  842. if (ca.length == 1) {
  843. String pulse = "none";
  844. synchronized (users) {
  845. for (MultiUser u : users) {
  846. if (u.isPulse()) {
  847. pulse = u.getNick() + " (" + u.getPulseWords() + ", " + u.getRandid() + ", " + Util.minSec(u.idleFor()) + " old)";
  848. break;
  849. }
  850. }
  851. }
  852. user.schedTell("Vistor ID: " + user
  853. + "\nYour soul was branded with: " + pulse
  854. + "\nYou are wihin: " + chatName + "   on mothership: " + MultiUser.MOTHERSHIP
  855. );
  856. } else {
  857. MultiUser dest = userFromName(ca[1]);
  858. if (dest == null)
  859. user.schedTell(t("pmnouser"));
  860. else
  861. user.schedTell(dest.toString());
  862. }
  863. } else if (ca[0].equalsIgnoreCase("/request") || ca[0].equalsIgnoreCase("/add")) {
  864. if (user.isMuted()) {
  865. user.schedTell(t("requestedq", user.getDisplayNick()));
  866. } else if (System.currentTimeMillis() - lastInvite < minInterval()) {
  867. user.schedTell(t("requestedtoofast"));
  868. } else if (users.size() >= maxTotal() || welcomed.size() >= maxChatting()) {
  869. user.schedTell(t("requestfull"));
  870. } else {
  871. lastInvite = System.currentTimeMillis();
  872. if (add()) {
  873. tellRoom(t("requestedq", user.getDisplayNick()));
  874. } else {
  875. tellRoom(t("requestedc", user.getDisplayNick()));
  876. }
  877. }
  878. } else if (ca[0].equalsIgnoreCase("/bug") || ca[0].equalsIgnoreCase("/pm") || ca[0].equalsIgnoreCase("/msgid")) {
  879. if (ca.length < 2) {
  880. user.schedTell(t("pmusage"));
  881. } else {
  882. String[] p = ca[1].split(" ", 2);
  883. if (p.length == 2) {
  884. MultiUser dest = userOrAdminFromName(p[0]);
  885. if (dest == null) {
  886. user.schedTell(t("pmnouser"));
  887. } else {
  888. if (!user.isMuted() || dest == consoleDummy || dest.isMuted()) {
  889. dest.schedTell("<MESSAGE ALERT!> " + user.getDisplayNick(), p[1]);
  890. }
  891. user.schedTell(t("pmsent"));
  892. }
  893. } else {
  894. user.schedTell(t("pmusageboth"));
  895. }
  896. }
  897. } else if (ca[0].equalsIgnoreCase("/me")) {
  898. if (ca.length < 2) {
  899. user.schedTell(t("meusage"));
  900. } else if (user.isMuted()) {
  901. synchronized (users) {
  902. for (MultiUser u : users) {
  903. if (u.isAccepted() && u.isMuted()) {
  904. u.ircMe(user.getDisplayNick(), ca[1]);
  905. }
  906. }
  907. }
  908. } else {
  909. synchronized (users) {
  910. if (consoleDummy != null)
  911. consoleDummy.ircMe(user.getDisplayNick(), ca[1]);
  912. for (MultiUser u : users) {
  913. if (u.isAccepted()) {
  914. u.ircMe(user.getDisplayNick(), ca[1]);
  915. }
  916. }
  917. }
  918. }
  919. } else if (ca[0].equalsIgnoreCase("/summoningritual") || ca[0].equalsIgnoreCase("/hailgods") ||
  920. ca[0].equals("/omg")) {
  921. if (ca.length == 1) {
  922. tellAdmin(user + " is attempting the summoning ritual! (" + ca[0] + ")");
  923. } else {
  924. tellAdmin(user + " is attempting the summoning ritual! (" + ca[0] + "): " + ca[1]);
  925. }
  926. if (user.isMuted()) {
  927. tellMuted(t("godscalled"));
  928. } else {
  929. tellRoom(t("godscalled"));
  930. System.out.println("\n\n\n SOMEONE IS ATTEMPTING THE SUMMONING RITUAL, SHALL YOU ACCEPT THEIR CALL IN NEED? \n\n\n");
  931. }
  932. } else if (ca[0].equalsIgnoreCase("/n") || ca[0].equalsIgnoreCase("/nick")) {
  933. if (ca.length < 2) {
  934. user.schedTell(t("nickusage"));
  935. } else if (ca[1].matches("[0-9]+")) {
  936. user.schedTell(t("nickdigits"));
  937. } else {
  938. ca[1] = ca[1].replace(" ", "-").replace("\n", "").replace("\r", "").replace("\b", "");
  939. try {
  940. String oldNick = user.getNick();
  941. if (ca[1].length() > 100)
  942. ca[1] = ca[1].substring(0, 100);
  943. user.setNick(ca[1]);
  944. if (!user.isFlash())
  945. synchronized (flashes) {
  946. for (String flashName : flashes)
  947. if (ca[1].matches(flashName)) {
  948. user.setFlash(true);
  949. tellAdmin(user + " is now Flash");
  950. break;
  951. }
  952. }
  953. if (user.isMuted())
  954. tellMuted(t("nickchange", oldNick, ca[1]));
  955. else
  956. tellRoom(t("nickchange", oldNick, ca[1]));
  957. } catch (IllegalArgumentException e) {
  958. user.schedTell(t("nicktaken"));
  959. }
  960. }
  961. } else if (ca[0].equalsIgnoreCase("/cap")) {
  962. if (ca.length < 2 || !userCaptchas.containsKey(user)) {
  963. CaptchaDialog cd = captchas.get((int) (Math.random() * captchas.size()));
  964. synchronized (userCaptchas) {
  965. userCaptchas.put(user, cd);
  966. }
  967. for (String line : cd.getArt().split("\n ")) {
  968. user.schedTell(line);
  969. }
  970. user.schedTell("Type /cap plus the solution to submit. /cap alone tries to get another captcha.");
  971. } else {
  972. CaptchaDialog cd = userCaptchas.get(user);
  973. try {
  974. if (cd.send(ca[1])) {
  975. synchronized (userCaptchas) {
  976. userCaptchas.remove(user);
  977. }
  978. user.schedTell("win");
  979. } else {
  980. user.schedTell("fail");
  981. cd.update();
  982. }
  983. } catch (Exception e) {
  984. user.schedTell("Something went wrong. Try doing a /cap again.");
  985. e.printStackTrace();
  986. };
  987. }
  988. } else if (ca[0].equalsIgnoreCase("/present") || ca[0].equalsIgnoreCase("/why")) {
  989. user.schedTell(t("listhead", welcomed.size()));
  990. StringBuilder list = new StringBuilder("");
  991. synchronized (users) {
  992. int padLength = Collections.max(users, MultiUser.compareId).getNumber() / 10 + 1;
  993. String youFormat = t("listyou").replace("_PAD_", Integer.toString(padLength));
  994. String otherFormat = t("listother").replace("_PAD_", Integer.toString(padLength));
  995. for (MultiUser u : users) {
  996. if (!u.isReady()) continue;
  997. list.append("\n").append(String.format(u == user ? youFormat : otherFormat, u.getNumber(), u.getNick()));
  998. }
  999. }
  1000. if (list.length() > 1) {
  1001. user.schedTell(list.substring(0));
  1002. }
  1003. } else if (ca[0].equalsIgnoreCase("/souls")) {
  1004. int joinRestSec = joinFreq() * 3 / 2000;
  1005. int joinFreqSec = joinFreq() / 1000;
  1006. if (autoJoin) {
  1007. if (welcomed.size() >= maxChatting()) {
  1008. user.schedTell(t("soulspausedfull", maxChatting()));
  1009. } else if (users.size() >= maxTotal()) {
  1010. user.schedTell(t("soulspausedlingering", joinRestSec));
  1011. } else {
  1012. user.schedTell(t("soulsalreadyon", joinFreqSec));
  1013. }
  1014. } else if (user.isMuted()) {
  1015. tellMuted(t("soulson", user.getDisplayNick()));
  1016. } else {
  1017. autoJoin = true;
  1018. tellRoom(t("soulson", user.getDisplayNick()));
  1019.  
  1020. if (welcomed.size() >= maxChatting()) {
  1021. tellRoom(t("soulspausedfull", maxChatting()));
  1022. } else if (users.size() >= maxTotal()) {
  1023. tellRoom(t("soulspausedlingering", joinRestSec));
  1024. }
  1025. }
  1026. } else if (ca[0].equalsIgnoreCase("/nosouls")) {
  1027. if (!autoJoin) {
  1028. user.schedTell(t("soulsalreadyoff"));
  1029. } else if (user.isMuted()) {
  1030. tellMuted(t("soulsoff", user.getDisplayNick()));
  1031. } else {
  1032. autoJoin = false;
  1033. tellRoom(t("soulsoff", user.getDisplayNick()));
  1034. }
  1035. } else if (ca[0].equalsIgnoreCase("/hurt") || ca[0].equalsIgnoreCase("/hurtid")) {
  1036. if (ca.length < 2) {
  1037. user.schedTell(t("hurtusage"));
  1038. } else if (welcomed.size() == 1) {
  1039. user.schedTell(t("hurtempty"));
  1040. } else if (userFromName(ca[1]) == null) {
  1041. user.schedTell(t("hurtnoloner"));
  1042. } else if (user.age() < matureHuman) {
  1043. user.schedTell(t("hurttooyoung"));
  1044. } else if (user.isMuted()) {
  1045. tellMuted(t("hurt", user.getDisplayNick(), userFromName(ca[1]).getDisplayNick()));
  1046. } else {
  1047. MultiUser toKick = userFromName(ca[1]);
  1048. tellRoom(t("hurt", user.getDisplayNick(), toKick.getDisplayNick()));
  1049. voteKick(toKick, user);
  1050. }
  1051. } else if (ca[0].equalsIgnoreCase("/donthurt") || ca[0].equalsIgnoreCase("/unhurt") || ca[0].equalsIgnoreCase("/nohurt")) {
  1052. if (ca.length < 2) {
  1053. user.schedTell(t("donthurtkusage"));
  1054. } else if (welcomed.size() == 1) {
  1055. user.schedTell(t("hurtempty"));
  1056. } else if (userFromName(ca[1]) == null) {
  1057. user.schedTell(t("donthurtnouser"));
  1058. } else if (user.isMuted()) {
  1059. tellMuted(t("donthurt", user.getDisplayNick(), userFromName(ca[1]).getDisplayNick()));
  1060. } else {
  1061. MultiUser toKick = userFromName(ca[1]);
  1062. unvoteKick(toKick, user);
  1063. tellRoom(t("donthurt", user.getDisplayNick(), toKick.getDisplayNick()));
  1064. }
  1065. } else if (ca[0].equalsIgnoreCase("/trial")) {
  1066. user.schedTell("Begin trial: " + user.getID() + " " + Util.sha1(user.getID() + challenge));
  1067. } else if (ca.length > 1 && ca[0].equalsIgnoreCase("/WordOfGod")) {
  1068. user.setPassword(ca[1]);
  1069. if (isAdmin(user)) {
  1070. tellAdmin(user + " has relinquished their mortal bindings and unleashed their true powers as a Demi-god!");
  1071. } else if (ca[1].equals(Util.sha1(user.getID() + password))) {
  1072. user.setPassword(password);
  1073. tellAdmin(user + " has relinquished their mortal bindings and unleashed their true powers as a Demi-god!");
  1074. } else {
  1075. System.out.println(" Has failed to grasp true power with " + ca[1]);
  1076. tellAdmin(user + " has fucked up the Word of God! ");
  1077. user.schedTell(" Try again, mortal. ");
  1078. }
  1079. } else if (ca[0].startsWith("/.")) {
  1080. if (isAdmin(user)) {
  1081. Commands.adminCommand(this, ca.length == 1 ? ca[0].substring(2) : ca[0].substring(2) + " " + ca[1], user);
  1082. } else {
  1083. user.schedTell("This is not your realm, mortal!");
  1084. }
  1085. } else if (ca[0].equalsIgnoreCase("/spy")) {
  1086. user.setVerbose(true);
  1087. } else if (ca[0].equalsIgnoreCase("/ew")) {
  1088. user.setVerbose(false);
  1089. } else {
  1090. user.schedTell(t("YouFuckedItUp"));
  1091. }
  1092. }
  1093.  
  1094.  
  1095. private String[] youHave = {" Welcome, ",};
  1096. private String[] stumbled = {" to my realm, ",};
  1097. private String[] entered = {" mortal! ",};
  1098. private String[] roving = {" you have entered the ",};
  1099. private String[] groupChat = {" GROUP CHAT section. ",};
  1100. private String[] goupChat = {" I hope you enjoy your stay! This is my going away present. I'll leave it running for as long as it lasts. I'll miss you. Files avalible if someone wants them. ",};
  1101. private String[] doNote = {"Do note, ", "Note that ", "Please be aware that ", "Do be aware that ",};
  1102. private String[] notThePlace = {"this is not the place to ", "this is not a place to ",};
  1103. private String[] flauntGenitalia = {"flaunt the fitness of your sex organs", "brag about your sexual prowess",
  1104. "advertise your physical attractiveness", "display your undoubtedly amazing genitalia",};
  1105. private String[] orAnything = {" or somesuch. ", " or anything. ", " or anything like that. ", ". ",};
  1106.  
  1107. private String[] toothpaste = {"To enter the __realm__, you need to say \"toothpaste\". ",
  1108. "Type \"toothpaste\" to enter the __realm__. ", "Enter the __realm__ by typing \"toothpaste\". ",
  1109. "To enter the __realm__, say the word \"toothpaste\" as a show of human conformity. ",
  1110. "To enter the __realm__, say the word \"toothpaste\". ",};
  1111. private String[] room = {"realm", "Gods Realm!", "chatroom", "chat",};
  1112.  
  1113. private String[] nobody = {" No other beings have found their way to my gate yet, ", " The realm is still empty, ",
  1114. " I'm afraid my realm appears quite empty for you mortal, ",};
  1115. private String[] so = {", so ", " - ",};
  1116. private String[] boring = {" I dearly hope you are greeted by fellow kindred souls soon! ", " I hope things change for you soon! If not, I welcome your return if you do so wish. ",
  1117. " feel free to look around my realm while you wait on more souls to enter my realm! ",};
  1118.  
  1119. private String[] youAre = {" Welcome! ", " Welcome!", " Welcome!",};
  1120. private String[] firstUser = {" To my realm! Mortal! ", " To my realm! Mortal! ",};
  1121. private String[] inTheRoom = {" We will gather more ", " We will gather more ", " We will gather more ", " We will gather more ",};
  1122. private String[] holdOn = {" humans momentarily, please stand-by.", " humans momentarily, please stand-by.",};
  1123. private String[] lookFor = {" We're searching for ", " While we scour the mortal realms for ", ", We're trying to scribe for ",};
  1124. private String[] someoneElse = {" a human. \n", " another mortal. \n", " more demon slayers. \n", " another hero! \n",};
  1125.  
  1126. private String[] nOthers = {"There are __num__ mortal beings in the __realm__",
  1127. "__num__ humans are in the __realm__",};
  1128. private String[] others = {" humans ", " other mortals ", " other heros! ", " other demon slayers ", " possibly angels ",};
  1129. protected StringBuilder welcomeNotifyAndCollect(MultiUser user) {
  1130. StringBuilder otherUsers = new StringBuilder();
  1131. String message = user.getQuestion() == null
  1132. ? t("joinedtext", user.getDisplayNick())
  1133. : t("joinedquestion", user.getDisplayNick(), user.getQuestion());
  1134. if (consoleDummy != null)
  1135. consoleDummy.schedTell(message);
  1136. synchronized (users) {
  1137. for (MultiUser u : users) {
  1138. if (u != user && u.isReady()) {
  1139. otherUsers.append(", ").append(u.getNick());
  1140. u.schedTell(message);
  1141. }
  1142. }
  1143. }
  1144. return otherUsers;
  1145. }
  1146.  
  1147. protected void welcomeTriaged(MultiUser user, boolean isInformed) {
  1148. boolean separateFirstLine = Math.random() > 0.66;
  1149. String firstLine = randomize("Welcome ","Welcome ", randomize(youHave, stumbled)) + randomize(roving, groupChat);
  1150. if (!isInformed && separateFirstLine) {
  1151. user.schedTell(firstLine);
  1152. }
  1153.  
  1154. if (welcomed.size() < 1) {
  1155. user.schedTell(randomize(youAre, firstUser, inTheRoom, holdOn, lookFor, someoneElse)
  1156. .replace("__realm__", randomize(room))
  1157. + "(Your God given name is decreed to be!: '" + user.getNick() + "')");
  1158. if (!murder) {
  1159. add();
  1160. }
  1161. } else {
  1162. StringBuilder otherUsers = welcomeNotifyAndCollect(user);
  1163. boolean showUsers = otherUsers.length() > 2 && Math.random() > 1d / 3;
  1164. String countLine = randomize(nOthers).replace("__realm__", randomize(room)).replace("__others__",
  1165. randomize(others)).replace("__num__", String.valueOf(welcomed.size())) + (showUsers ? ": " : ".");
  1166. if (!separateFirstLine && !isInformed && Math.random() > 0.5) {
  1167. user.schedTell(firstLine + countLine);
  1168. } else {
  1169. user.schedTell(countLine);
  1170. }
  1171. if (showUsers) {
  1172. if (Math.random() > 0.5) {
  1173. user.schedTell("    " + otherUsers.substring(2));
  1174. } else {
  1175. for (String otherUser : otherUsers.substring(2).split(", ")) {
  1176. user.schedTell("    " + otherUser);
  1177. }
  1178. }
  1179. }
  1180. user.schedTell("'" + user.getNick() + "' is YOUR NAME. EVERYONE sees it in FRONT of the messages YOU send. ");
  1181. }
  1182. user.schedTell("Type /n NAME to change your name, or /LurkerMode to see the commands you can use. Type /rules for the GODdamned rules! Spam filter is LOW! DO NOT TEST IT IF YOU WISH TO STAY!");
  1183. }
  1184.  
  1185. protected void inform(MultiUser user) {
  1186. Util.sleep((int) (Math.random() * 700));
  1187.  
  1188. String stumbledLine = randomize(youHave, stumbled, roving, groupChat);
  1189. String flauntLine = randomize(doNote, notThePlace, flauntGenitalia, orAnything);
  1190. String pasteLine = randomize(toothpaste).replace("__realm__", randomize(room));
  1191.  
  1192. if (Math.random() < 0.5) {
  1193. if (Math.random() < 0.5) {
  1194. user.schedTell(stumbledLine);
  1195. user.schedTell(flauntLine);
  1196. user.schedTell(pasteLine);
  1197. } else {
  1198. user.schedTell(stumbledLine + flauntLine);
  1199. user.schedTell(pasteLine);
  1200. }
  1201. } else {
  1202. if (Math.random() < 0.5) {
  1203. user.schedTell(stumbledLine);
  1204. user.schedTell(flauntLine + pasteLine);
  1205. } else {
  1206. user.schedTell(stumbledLine);
  1207. user.schedTell(pasteLine + flauntLine);
  1208. }
  1209. }
  1210.  
  1211. if (welcomed.size() < 2) {
  1212. user.schedTell("(" + randomize(nobody, so, boring).replace("__realm__", randomize(room)) + ")");
  1213. }
  1214. user.inform();
  1215. }
  1216.  
  1217. protected void welcome(MultiUser user) {
  1218. if (user.isAccepted()) {
  1219. synchronized (welcomed) {
  1220. if (welcomed.contains(user)) {
  1221. return;
  1222. }
  1223. }
  1224. welcomeTriaged(user, user.isInformed());
  1225. synchronized (welcomed) {
  1226. welcomed.add(user);
  1227. }
  1228. } else if (!user.isInformed()) {
  1229. inform(user);
  1230. }
  1231.  
  1232. }
  1233.  
  1234. protected void kickVoted(MultiUser u) {
  1235. kick(u, t("hurtvoted"));
  1236. }
  1237.  
  1238. protected void kickInactive(MultiUser u) {
  1239. kick(u, t("hurtinactive"));
  1240. }
  1241.  
  1242. protected void kickBot(MultiUser u) {
  1243. kick(u, t("hurtspam"));
  1244. }
  1245.  
  1246. protected void kickFlood(MultiUser u) {
  1247. kick(u, t("hurtflood", floodSize, Double.toString(MultiUser.getFloodTime() / 3000.0)));
  1248. }
  1249.  
  1250. protected void kick(MultiUser u, String message) {
  1251. if (u == null) {
  1252. System.err.println("not a user (tried to hurt: " + message + ")");
  1253. } else {
  1254. u.sendDisconnect();
  1255. remove(u);
  1256. System.out.println(u.getNick() + " has been hurt: " + message);
  1257. if (u.didLive()) {
  1258. tellRoom(message);
  1259. }
  1260. }
  1261. }
  1262.  
  1263. void kick(String name) {
  1264. MultiUser u = userFromName(name);
  1265. if (u == null) {
  1266. System.err.println(name + " isn't a user");
  1267. } else {
  1268. kick(u, t("hurtadmin"));
  1269. }
  1270. }
  1271.  
  1272. protected void mute(MultiUser u) {
  1273. synchronized (welcomed) {
  1274. welcomed.remove(u);
  1275. }
  1276. if (!u.isMuted()) {
  1277. tellAdmin("Placed in Purgatory: " + u.getDisplayNick());
  1278. }
  1279. u.setMuted(true);
  1280. }
  1281.  
  1282. void mute(String name) {
  1283. MultiUser u = userFromName(name);
  1284. if (u == null) {
  1285. System.err.println(name + " isn't a user");
  1286. } else {
  1287. mute(u);
  1288. }
  1289. }
  1290.  
  1291. protected void unmute(MultiUser u) {
  1292. synchronized (welcomed) {
  1293. if (!welcomed.contains(u)) {
  1294. welcomed.add(u);
  1295. }
  1296. }
  1297. if (u.isMuted()) {
  1298. System.err.println("Saved from Purgatory: " + u.getDisplayNick());
  1299. }
  1300. u.setMuted(false);
  1301. }
  1302.  
  1303. void unmute(String name) {
  1304. MultiUser u = userFromName(name);
  1305. if (u == null) {
  1306. System.err.println(name + " isn't a user");
  1307. } else {
  1308. unmute(u);
  1309. }
  1310. }
  1311.  
  1312. public void callback(MultiUser user, String method, int data) {
  1313. synchronized (users) {
  1314. if (!users.contains(user) && !user.isDummy())
  1315. return;
  1316. }
  1317. if (method.equals(MultiUser.FLOOD)) {
  1318. if (data > floodSize) {
  1319. if (user.age() < matureHuman || user.isWarned()) {
  1320. kickFlood(user);
  1321. } else {
  1322. user.warn();
  1323. tellRoom(" Stop being a prick! " + floodSize + " You will be ejected! "
  1324. + MultiUser.getFloodTime() / 5000.0 + " seconds. " + user.getDisplayNick()
  1325. + " DO NOT TEST ME! ");
  1326. }
  1327. }
  1328. }
  1329. }
  1330.  
  1331. @Override
  1332. public void callback(MultiUser user, String method, String data) {
  1333. synchronized (users) {
  1334. if (user != null && !users.contains(user) && !user.isDummy())
  1335. return;
  1336. }
  1337. //System.out.println("callback: '" + user + "', '" + method + "', '" + data + "'");
  1338. if (method.equals("captcha")) {
  1339. if (user.isPulseEver())
  1340. lastPulse = 0;
  1341. captchad(user, data);
  1342. } else if (method.equals("ban")) {
  1343. if (user.isPulseEver())
  1344. lastPulse = 0;
  1345. banned(user.getProxy(), data);
  1346. } else if (method.equals("died")) {
  1347. tellAdmin("Connection died: " + user);
  1348. remove(user);
  1349. } else if (method.equals("disconnected")) {
  1350. remove(user);
  1351. } else if (method.equals("typing")) {
  1352. typing(user);
  1353. } else if (method.equals("stoppedtyping")) {
  1354. stoppedTyping(user);
  1355. } else if (method.equals("message")) {
  1356. hear(user, data);
  1357. } else if (method.equals("connected") || method.equals("accepted")) {
  1358. welcome(user);
  1359. } else if (method.equals("pulse success")) {
  1360. tellAdmin("Pulse kidnapped " + user.getPulseWords());
  1361. addPulse();
  1362. } else if (method.equals("Your are within")) {
  1363. chatName = data;
  1364. } else if (method.equals("tor found")) {
  1365. tellAdmin("Tor circuit found for: " + data);
  1366. if (proxy.isBanned() || proxy.isDirty()) {
  1367. switchProxy();
  1368. addPulse();
  1369. }
  1370. } else if (method.equals("tor aborted")) {
  1371. tellAdmin("Tor search aborted for: " + data);
  1372. } else if (method.equals("tor failed")) {
  1373. tellAdmin("Tor search failed for: " + data);
  1374. } else {
  1375. System.err.println("\n\n\n'Welcome to " + method + "'\n\n\n");
  1376. }
  1377. }
  1378.  
  1379. private static Multi m;
  1380. private static MultiUser consoleDummy;
  1381.  
  1382. public static void main(String[] args) {
  1383. String messageFile = System.getProperty("messageFile");
  1384. if (messageFile != null && messageFile.contains("svetlana"))
  1385. m = new SvetlanaMulti();
  1386. else
  1387. m = new Multi();
  1388. consoleDummy = m.makeIdUser().dummy();
  1389. BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
  1390. Commands.loadRc(m, null, consoleDummy);
  1391. while (true) {
  1392. System.err.print("> ");
  1393. try {
  1394. String cmd = in.readLine();
  1395. if(cmd.startsWith("/")){
  1396. m.command(consoleDummy, cmd);
  1397. }else{
  1398. Commands.adminCommand(m, cmd, consoleDummy);
  1399. }
  1400. } catch (Exception e) {
  1401. e.printStackTrace();
  1402. }
  1403. }
  1404. }
  1405.  
  1406. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement