Emberveil source

tests/WelcomeMessageCheck.java

import com.rs2.Constants;
import com.rs2.game.players.Client;
import com.rs2.util.Stream;
import java.nio.charset.StandardCharsets;
import java.util.*;
public final class WelcomeMessageCheck {
 static void check(boolean ok,String message){if(!ok)throw new AssertionError(message);}
 static List<String> messages(Client p) {
  Stream stream=p.getOutStream();List<String> result=new ArrayList<>();
  for(int at=0;at<stream.currentOffset;) {
   at++;int length=stream.buffer[at++]&255;
   check(length>0&&at+length<=stream.currentOffset,"valid packet length");
   check(stream.buffer[at+length-1]==10,"message terminator");
   result.add(new String(stream.buffer,at,length-1,StandardCharsets.ISO_8859_1));at+=length;
  }
  return result;
 }
 public static void main(String[] args) {
  Client p=new Client(null,1);p.getOutStream().packetEncryption=new org.apollo.util.security.IsaacRandom(new int[]{1,2,3,4});
  p.getPacketSender().sendMessage(Constants.welcomeMessage());List<String> lines=messages(p);
  check(lines.size()==3,"exactly three welcome lines");
  for(String line:lines)check(line.startsWith("@cya@")&&line.length()<100,"cyan readable line");
  check(lines.get(0).contains("bonds")&&lines.get(0).contains("old-school"),"owner and classic identity");
  check(lines.get(1).contains("PvM")&&lines.get(1).contains("Slayer"),"bossing and Slayer");
  check(lines.get(2).contains("Wilderness")&&lines.get(2).contains("PvP"),"PvP location clear");
  p.getOutStream().currentOffset=0;p.getPacketSender().sendMessage("An ordinary message");
  check(messages(p).equals(Collections.singletonList("An ordinary message")),"ordinary chat unchanged");
  System.out.println("PASS cyan welcome packets, owner, PvM/Slayer/PvP copy and unchanged normal chat");
 }
}