Graal Pastebin

New Paste
Pasted on January 28, 2011.
View the raw file

this.join("utility_time");
 
/**
 * Available group types:
 * A - global chat - filled with toall:
 * V - vulgar chat - automatically filled with vulgar chat
 * E - events - for relaying event information
 *
 * The underlying line type: 
 * A 4-tuple : {account, timeAdded, input, broadcasted}
 *
 * @author WhiteDragon
 * @return null
 */
function onCreated() {
  this.bannedaccounts = {"GraalianNoob", "danixfun", "Graal764768"};
  onInitialized();
}
 
/**
 * @return null
 */
function onInitialized() {
  //this.c.A.chat.delete(this.c.A.chat.size() - 1);
  this.maxLines = 20; // max lines of text stored in a single group
  if(this.c == NULL){
    this.c = new TStaticVar(); // hash that stores all groups
  }
  system_chat = this;
}
 
/**
 * Add a player to groups.
 * @param object(TServerPlayer) The player.
 * @return null
 */
public function playerLoggedIn(temp.pl){
  this.addPlayerGroup("A", temp.pl.getName());
  this.addPlayerGroup("S", temp.pl.getName());
  if(temp.pl.guild != NULL){
    this.addPlayerGroup("G" @ temp.pl.guild, temp.pl.getName());
  }
}
 
/**
 * Add a new line to a group, broadcast the change, and then garbage collect any old lines.
 *
 * @param string Group for the line to be added to
 * @param string Account of the person who is adding the text
 * @param string The contents of the line
 * @return null
 */
public function addLine(temp.group, temp.account, temp.input) {
  if (!groupExists(temp.group)) { // check if group doesn't already exist
    createGroup(temp.group);  // if so, make it
  }
  switch(temp.group){
    case "A":
      savelog2("log_toalls.txt", temp.account @ ": " @ temp.input);
    case "G":
      temp.date = this.getDate(timevar2);
      temp.input @= " (" @ temp.date[2] SPC this.getFormalMonthEnglish(temp.date[1]).substring(0,3) SPC temp.date[0].substring(2,2) @ ")";
    break;
  }
  this.c.(@temp.group).chat.add({temp.account, timevar2, temp.input, false}); // add the line to the group
  broadcastGroup(temp.group); // broadcast to all the online players who are in the group the new messages
 
  garbageCollect(temp.group); // get rid of old lines
}
 
/**
 * Remove all the old lines from a group.
 *
 * @param string Group the lines will be removed from.
 * @return null
 */
function garbageCollect(temp.group) {
  while (this.c.(@temp.group).chat.size() > this.maxLines) { // while there are more than this.maxLines
    this.c.(@temp.group).chat.delete(0); // delete the oldest line
  }
}
 
/**
 * Check if a group exists
 *
 * @param string Group name.
 * @return int Group exists.
 */
function groupExists(temp.group) {
  return (this.c.(@temp.group) != null);
}
 
 
/**
 * Create a new group.
 *
 * @param string Group name
 * @return null
 */
function createGroup(temp.group) {
  this.c.(@temp.group) = new TStaticVar();
  this.c.(@temp.group).chat = {};
  this.c.(@temp.group).onlinePlayers = {};
}
 
/**
 * Broadcast all the new lines of a group to all the online players in the group.
 *
 * @param string Group name
 * @return null
 */
function broadcastGroup(temp.group) {
  temp.newLines = {};
  for (temp.i = this.c.(@temp.group).chat.size()-1; temp.i >= 0; temp.i--) { // check every line starting from end
    if (!this.c.(@temp.group).chat[temp.i][3]) { // to see if it hasn't already been broadcasted
      this.c.(@temp.group).chat[temp.i][3] = true;
      temp.newLines.insert(0, this.c.(@temp.group).chat[temp.i]); // add it to the lines to send 
    } else { // otherwise
      break; // stop looking
    }
  }
 
  for ( temp.p : this.c.(@temp.group).onlinePlayers ) { // for all the online players
    findPlayer(temp.p).triggerclient("weapon", "-System-Chat", "addLines", temp.group, temp.newLines); // send the new lines
  }
}
 
/**
 * Send all the lines of a group to a player.
 *
 * @param string Group name
 * @param object(TServerPlayer) Player object
 * @return null
 */
function sendGroup(temp.group, temp.player) {
  temp.player.triggerclient("weapon", "-System-Chat", "addLines", temp.group, this.c.(@temp.group).chat); // send all the lines to the player
}
 
/**
 * Add a player to a group.
 * @param string Group.
 * @param string Player account.
 * @return null
 */
public function addPlayerGroup(temp.group, temp.account) {
  if (!groupExists(temp.group)) { // check if group doesn't already exist
    createGroup(temp.group);  // if so, make it
  }
  if (this.c.(@temp.group).onlinePlayers.index(temp.account) == -1) {
    this.c.(@temp.group).onlinePlayers.add(temp.account); // add account to onlinePlayers array
  }
}
 
/**
 * Remove a player from a group.
 * @param string Group name.
 * @param string Player account.
 * @return null
 */
public function removePlayerGroup(temp.group, temp.account) {
  if (!groupExists(temp.group)) { // check if group doesn't already exist
    createGroup(temp.group);  // if so, make it
  }
  this.c.(@temp.group).onlinePlayers.remove(temp.account); // remove account from onlinePlayers array
}
 
/**
 * Route serverside triggers.
 * @return null
 */
function onActionServerside() {
  if (params[0] == "requestGroup") {
    sendGroup(params[1], player);
  } else if (params[0] == "addLine") {
    if(this.canChat(player)){
      temp.displayName = player.getName();
      addLine(params[1], temp.displayName, params[2]);
    }
  } else if (params[0] == "removeFromGroup") {
    removePlayerGroup(params[1], player.getName());
  } else if (params[0] == "addToGroup") {
    addPlayerGroup(params[1], player.getName());
  }
}
 
/**
 * Send a single message to a player.
 * @param object(TServerPlayer) Player.
 * @param string The group name to "fake" the message under.
 * @param string The message.
 * @return null
 */
public function singleMessage(temp.pl, temp.group, temp.message){
  temp.pl.triggerclient("gui", "-System-Chat", "addLines", temp.group, {{NULL, timevar2, temp.message, true}});
}
 
/**
 * Remove a player from their groups.
 * @param object(TServerPlayer) Player.
 * @return null
 */
public function playerLoggedOut(temp.p) {
  if(temp.p.level == NULL){
    return;
  }
  removePlayerGroup("G"@temp.p.guild, temp.p.getName());
  removePlayerGroup("A", temp.p.getName());
  removePlayerGroup("S", temp.p.getName());
}
 
/**
 * Check if a player is allowed to chat.
 * @param object(TServerPlayer) Player.
 * @return int Allowed to chat.
 */
function canChat(temp.pl){
  if(temp.pl.isJailed()){
    return false;
  }
  if(this.bannedaccounts.index(temp.pl.account) > -1){
    return false;
  }
  return true;
}
  • 1
  • 2
  • 3
  • 4
  • 5
  • 6
  • 7
  • 8
  • 9
  • 10
  • 11
  • 12
  • 13
  • 14
  • 15
  • 16
  • 17
  • 18
  • 19
  • 20
  • 21
  • 22
  • 23
  • 24
  • 25
  • 26
  • 27
  • 28
  • 29
  • 30
  • 31
  • 32
  • 33
  • 34
  • 35
  • 36
  • 37
  • 38
  • 39
  • 40
  • 41
  • 42
  • 43
  • 44
  • 45
  • 46
  • 47
  • 48
  • 49
  • 50
  • 51
  • 52
  • 53
  • 54
  • 55
  • 56
  • 57
  • 58
  • 59
  • 60
  • 61
  • 62
  • 63
  • 64
  • 65
  • 66
  • 67
  • 68
  • 69
  • 70
  • 71
  • 72
  • 73
  • 74
  • 75
  • 76
  • 77
  • 78
  • 79
  • 80
  • 81
  • 82
  • 83
  • 84
  • 85
  • 86
  • 87
  • 88
  • 89
  • 90
  • 91
  • 92
  • 93
  • 94
  • 95
  • 96
  • 97
  • 98
  • 99
  • 100
  • 101
  • 102
  • 103
  • 104
  • 105
  • 106
  • 107
  • 108
  • 109
  • 110
  • 111
  • 112
  • 113
  • 114
  • 115
  • 116
  • 117
  • 118
  • 119
  • 120
  • 121
  • 122
  • 123
  • 124
  • 125
  • 126
  • 127
  • 128
  • 129
  • 130
  • 131
  • 132
  • 133
  • 134
  • 135
  • 136
  • 137
  • 138
  • 139
  • 140
  • 141
  • 142
  • 143
  • 144
  • 145
  • 146
  • 147
  • 148
  • 149
  • 150
  • 151
  • 152
  • 153
  • 154
  • 155
  • 156
  • 157
  • 158
  • 159
  • 160
  • 161
  • 162
  • 163
  • 164
  • 165
  • 166
  • 167
  • 168
  • 169
  • 170
  • 171
  • 172
  • 173
  • 174
  • 175
  • 176
  • 177
  • 178
  • 179
  • 180
  • 181
  • 182
  • 183
  • 184
  • 185
  • 186
  • 187
  • 188
  • 189
  • 190
  • 191
  • 192
  • 193
  • 194
  • 195
  • 196
  • 197
  • 198
  • 199
  • 200
  • 201
  • 202
  • 203
  • 204
  • 205
  • 206
  • 207
  • 208
  • 209
  • 210
  • 211
  • 212
  • 213
  • 214
  • 215
  • 216
  • 217
  • 218
  • 219
  • 220
  • 221
  • 222
  • 223
  • 224