Source code: jcsq/rules/RulesPacketStripper.java
1 package jcsq.rules;
2
3 import jcsq.PacketStripper;
4 import java.util.Vector;
5
6 /**
7 * Fetches all rules into a Rules object.
8 */
9 public class RulesPacketStripper extends PacketStripper{
10
11 //private byte[] bytes;
12 Rules rules = new Rules();
13 public RulesPacketStripper(byte[] b){
14 super(b);
15 strip(6);
16 parseRules();
17 }
18
19 private void parseRules(){
20 int rulesCounter = 0;
21 boolean parsingFirst = true;
22 boolean parsingLast = false;
23 for(int i=0;i<this.bytes.length;i++){
24 byte currentByte = this.bytes[i];
25 //System.out.println(i+ " "+this.bytes[i]);
26 if(parsingFirst){
27 if(currentByte!=0){
28 rules.appendName(currentByte);
29 }
30 else{
31 parsingFirst = false;
32 parsingLast = true;
33 }
34 }
35 else if(parsingLast){
36 if(currentByte!=0){
37 rules.appendValue(currentByte);
38 }
39 else{
40 parsingLast = false;
41 parsingFirst = true;
42 rules.addCurrent();
43 rulesCounter++;
44 }
45 }
46 if(currentByte==0){
47 //hack
48 if(this.bytes[i-1]==0 && this.bytes[i-2]==0 && this.bytes[i-3]==0)
49 return;
50 }
51
52
53 }
54
55 }
56
57 public Rules getServerRules(){
58 return this.rules;
59 }
60
61 }