Skip to content
This repository has been archived by the owner on May 17, 2020. It is now read-only.

Commit

Permalink
Updated IPCPpacket and created PCP static class
Browse files Browse the repository at this point in the history
IPCPpacket
- packets now must implement byte[] header()
PCP
- class contains static util variables, like PORT
- static subclasses contain version specific variables
  • Loading branch information
JacopoWolf committed Nov 2, 2019
1 parent 4926461 commit 18642f5
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 15 deletions.
36 changes: 36 additions & 0 deletions PCP/src/main/java/PCP/PCP.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* this is a school project under "The Unlicence".
*/
package PCP;


/**
* static class utilities and most used values in the PCP protocol.
* @author Jacopo_Wolf
*/
public final class PCP
{

/**
* primary port to check for the server
*/
public static final int PORT = 53101;


/**
* PCP-Minimal
* @author Jacopo_Wolf
*/
public static class Min
{
/**
* maximum lenght of a single package
*/
public static final int MAX_PACKET_LENGHT = 2048;
}


// private constructor to avoid initialization
private PCP(){}

}
23 changes: 14 additions & 9 deletions PCP/src/main/java/PCP/packets/IPCPpacket.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,26 +13,31 @@
*/
public interface IPCPpacket
{
/**
* maximum lenght of a single package
*/
public static final int MAX_PACKET_LENGHT = 2048;


/**
* @return the opcode of this packet
*/
OpCode getOpCode();

/**
* Converts the packet to bytes to be sent.
* returs multiple byte arrays if the package exceeds maximum lenght.
* @return the collection of byte arrays payload to send.
* generates and returns the header of this particular packet.
* header's lenght is never superior to PACKET_MAX_LENGHT
* @return the header of this packet
*/
Collection<byte[]> toBytes();
byte[] header();

/**
* @return the total size of this packet
* calculates the total size of the packet, headers and payload included.
* @return the total size of this packet.
*/
int size();

/**
* Converts the packet to bytes to be sent.
* returs multiple byte arrays if the package exceeds maximum lenght.
* @return the collection of byte arrays payload to send.
*/
Collection<byte[]> toBytes();

}
6 changes: 3 additions & 3 deletions PCP/src/main/java/PCP/packets/PCPGroupUsersList.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
package PCP.packets;

import PCP.*;
import java.nio.charset.StandardCharsets;
import java.nio.charset.*;
import java.util.*;


Expand Down Expand Up @@ -82,11 +82,11 @@ public Collection<byte[]> toBytes()
int NpacketsToSent =
(
this.jsonContent.length() /
(IPCPpacket.MAX_PACKET_LENGHT - 4)
(PCP.Min.MAX_PACKET_LENGHT - 4)
)
+ 1 ;

int messageRelativeMaxLenght = IPCPpacket.MAX_PACKET_LENGHT - 4;
int messageRelativeMaxLenght = PCP.Min.MAX_PACKET_LENGHT - 4;


int messagePointer = 0;
Expand Down
6 changes: 3 additions & 3 deletions PCP/src/main/java/PCP/packets/PCPMsgUserToGroupPacket.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
package PCP.packets;

import PCP.*;
import java.nio.charset.StandardCharsets;
import java.nio.charset.*;
import java.util.*;

/**
Expand Down Expand Up @@ -70,11 +70,11 @@ public Collection<byte[]> toBytes()
int NpacketsToSent =
(
this.message.length() /
(IPCPpacket.MAX_PACKET_LENGHT - 4)
(PCP.MAX_PACKET_LENGHT - 4)
)
+ 1 ;

int messageRelativeMaxLenght = IPCPpacket.MAX_PACKET_LENGHT - 4;
int messageRelativeMaxLenght = PCP.MAX_PACKET_LENGHT - 4;


int messagePointer = 0;
Expand Down

0 comments on commit 18642f5

Please sign in to comment.