Skip to content
Snippets Groups Projects

Compare revisions

Changes are shown as if the source revision was being merged into the target revision. Learn more about comparing revisions.

Source

Select target project
No results found

Target

Select target project
No results found
Show changes
Commits on Source (10)
Showing
with 2036 additions and 0 deletions
/src/server/sisterServer/nbproject/private/
/src/server/sisterServer/build/
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<!-- You may freely edit this file. See commented blocks below for -->
<!-- some examples of how to customize the build. -->
<!-- (If you delete it and reopen the project it will be recreated.) -->
<!-- By default, only the Clean and Build commands use this build script. -->
<!-- Commands such as Run, Debug, and Test only use this build script if -->
<!-- the Compile on Save feature is turned off for the project. -->
<!-- You can turn off the Compile on Save (or Deploy on Save) setting -->
<!-- in the project's Project Properties dialog box.-->
<project name="sisterServer" default="default" basedir=".">
<description>Builds, tests, and runs the project sisterServer.</description>
<import file="nbproject/build-impl.xml"/>
<!--
There exist several targets which are by default empty and which can be
used for execution of your tasks. These targets are usually executed
before and after some main targets. They are:
-pre-init: called before initialization of project properties
-post-init: called after initialization of project properties
-pre-compile: called before javac compilation
-post-compile: called after javac compilation
-pre-compile-single: called before javac compilation of single file
-post-compile-single: called after javac compilation of single file
-pre-compile-test: called before javac compilation of JUnit tests
-post-compile-test: called after javac compilation of JUnit tests
-pre-compile-test-single: called before javac compilation of single JUnit test
-post-compile-test-single: called after javac compilation of single JUunit test
-pre-jar: called before JAR building
-post-jar: called after JAR building
-post-clean: called after cleaning build products
(Targets beginning with '-' are not intended to be called on their own.)
Example of inserting an obfuscator after compilation could look like this:
<target name="-post-compile">
<obfuscate>
<fileset dir="${build.classes.dir}"/>
</obfuscate>
</target>
For list of available properties check the imported
nbproject/build-impl.xml file.
Another way to customize the build is by overriding existing main targets.
The targets of interest are:
-init-macrodef-javac: defines macro for javac compilation
-init-macrodef-junit: defines macro for junit execution
-init-macrodef-debug: defines macro for class debugging
-init-macrodef-java: defines macro for class execution
-do-jar: JAR building
run: execution of project
-javadoc-build: Javadoc generation
test-report: JUnit report generation
An example of overriding the target for project execution could look like this:
<target name="run" depends="sisterServer-impl.jar">
<exec dir="bin" executable="launcher.exe">
<arg file="${dist.jar}"/>
</exec>
</target>
Notice that the overridden target depends on the jar target and not only on
the compile target as the regular run target does. Again, for a list of available
properties which you can use, check the target you are overriding in the
nbproject/build-impl.xml file.
-->
</project>
Manifest-Version: 1.0
X-COMMENT: Main-Class will be added automatically by build
This diff is collapsed.
build.xml.data.CRC32=98ebdcdd
build.xml.script.CRC32=02698be7
build.xml.stylesheet.CRC32=8064a381@1.75.2.48
# This file is used by a NetBeans-based IDE to track changes in generated files such as build-impl.xml.
# Do not edit this file. You may delete it but then the IDE will never regenerate such files for you.
nbproject/build-impl.xml.data.CRC32=98ebdcdd
nbproject/build-impl.xml.script.CRC32=2df7ba29
nbproject/build-impl.xml.stylesheet.CRC32=876e7a8f@1.75.2.48
annotation.processing.enabled=true
annotation.processing.enabled.in.editor=false
annotation.processing.processor.options=
annotation.processing.processors.list=
annotation.processing.run.all.processors=true
annotation.processing.source.output=${build.generated.sources.dir}/ap-source-output
build.classes.dir=${build.dir}/classes
build.classes.excludes=**/*.java,**/*.form
# This directory is removed when the project is cleaned:
build.dir=build
build.generated.dir=${build.dir}/generated
build.generated.sources.dir=${build.dir}/generated-sources
# Only compile against the classpath explicitly listed here:
build.sysclasspath=ignore
build.test.classes.dir=${build.dir}/test/classes
build.test.results.dir=${build.dir}/test/results
# Uncomment to specify the preferred debugger connection transport:
#debug.transport=dt_socket
debug.classpath=\
${run.classpath}
debug.test.classpath=\
${run.test.classpath}
# Files in build.classes.dir which should be excluded from distribution jar
dist.archive.excludes=
# This directory is removed when the project is cleaned:
dist.dir=dist
dist.jar=${dist.dir}/sisterServer.jar
dist.javadoc.dir=${dist.dir}/javadoc
excludes=
file.reference.commons-io-2.2.jar=src\\lib\\commons-io-2.2.jar
file.reference.json-simple-1.1.1.jar=src\\lib\\json-simple-1.1.1.jar
includes=**
jar.compress=false
javac.classpath=\
${file.reference.commons-io-2.2.jar}:\
${file.reference.json-simple-1.1.1.jar}
# Space-separated list of extra javac options
javac.compilerargs=
javac.deprecation=false
javac.processorpath=\
${javac.classpath}
javac.source=1.8
javac.target=1.8
javac.test.classpath=\
${javac.classpath}:\
${build.classes.dir}
javac.test.processorpath=\
${javac.test.classpath}
javadoc.additionalparam=
javadoc.author=false
javadoc.encoding=${source.encoding}
javadoc.noindex=false
javadoc.nonavbar=false
javadoc.notree=false
javadoc.private=false
javadoc.splitindex=true
javadoc.use=true
javadoc.version=false
javadoc.windowtitle=
main.class=sisterserver.SisterServer
manifest.file=manifest.mf
meta.inf.dir=${src.dir}/META-INF
mkdist.disabled=false
platform.active=default_platform
run.classpath=\
${javac.classpath}:\
${build.classes.dir}
# Space-separated list of JVM arguments used when running the project.
# You may also define separate properties like run-sys-prop.name=value instead of -Dname=value.
# To set system properties for unit tests define test-sys-prop.name=value:
run.jvmargs=
run.test.classpath=\
${javac.test.classpath}:\
${build.test.classes.dir}
source.encoding=UTF-8
src.dir=src
test.src.dir=test
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://www.netbeans.org/ns/project/1">
<type>org.netbeans.modules.java.j2seproject</type>
<configuration>
<data xmlns="http://www.netbeans.org/ns/j2se-project/3">
<name>sisterServer</name>
<source-roots>
<root id="src.dir"/>
</source-roots>
<test-roots>
<root id="test.src.dir"/>
</test-roots>
</data>
</configuration>
</project>
File added
File added
File added
File added
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package sisterserver;
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.net.Socket;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;
import java.util.ArrayList;
import java.util.logging.Level;
import java.util.logging.Logger;
import org.json.simple.JSONObject;
/**
*
* @author TOSHIBA
*/
public class Client extends Thread{
private Socket connSocket;
private String clientSentence;
private BufferedReader fromClient;
private DataOutputStream toClient;
public Client(Socket socket) throws IOException{
connSocket = socket;
}
public void run(){
try{
fromClient = new BufferedReader(new InputStreamReader(connSocket.getInputStream()));
toClient = new DataOutputStream(connSocket.getOutputStream());
clientSentence = fromClient.readLine();
toClient.writeBytes("Command Sent "+clientSentence);
// System.out.println("Sent "+clientSentence);
checkCmd(clientSentence);
}catch(IOException e){
System.out.println(e);
} catch (NoSuchAlgorithmException ex) {
Logger.getLogger(Client.class.getName()).log(Level.SEVERE, null, ex);
}
}
public void checkCmd(String cmd) throws IOException, NoSuchAlgorithmException{
//pengujian setiap appendix
System.out.println("cmd: "+cmd);
switch(cmd){
case "1" : System.out.println(getContent("167.205.32.46","join")); //OK
break;
case "2" :
System.out.println(serverStatus("167.205.32.46"));
break;
case "3" :
System.out.println(signUp("sister1234", "sistermania123")); //OK //using sha1
break;
case "4" :
System.out.println(login("sister1234", "sistermania123")); //OK //using sha1
// System.out.println(login("sister123", "1234")); //OK using md5
break;
case "5" :
System.out.println(inventoryInquire("f61de6dad9f2c042cfbdb1e96096b059")); //OK
break;
case "6" :
System.out.println(mixItem("f61de6dad9f2c042cfbdb1e96096b059", 2, 3)); //untested
break;
case "7" :
System.out.println(requestMap("f61de6dad9f2c042cfbdb1e96096b059")); //OK
break;
case "8" :
System.out.println(movePlayer("f61de6dad9f2c042cfbdb1e96096b059", 1, 2)); //OK
break;
case "9" :
System.out.println(getFromField("f61de6dad9f2c042cfbdb1e96096b059")); //OK
break;
case "A" :
System.out.println(offerToMarket("f61de6dad9f2c042cfbdb1e96096b059", 2, 1, 5, 1)); //OK //offer token f0a05df434dba4f49542b3e519448548
break;
case "B" :
System.out.println(myTradeBox("f61de6dad9f2c042cfbdb1e96096b059")); //OK
break;
}
}
public String getContent(String URL, String comnd) throws IOException{
//untuk melakukan join deengan tracker(Appendix A 1.1)
String response = "";
String request = "";
Socket miniSock = new Socket(URL, 8000);
JSONObject object = new JSONObject();
switch(comnd){
case "join":
object.put("method","join");
object.put("ip", "167.205.22.104");
object.put("port", 1234);
}
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(miniSock.getOutputStream())));
out.println(object);
out.println();
out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(miniSock.getInputStream()));
response = org.apache.commons.io.IOUtils.toString(in);
in.close();
return response;
}
public String serverStatus(String URL) throws IOException{
//untuk melakukan pengecekan status server(Appendix A 2.1)
String response = "";
String request = "";
Socket miniSock = new Socket(URL, 8025);
JSONObject object = new JSONObject();
object.put("method","serverStatus");
object.put("server", object.put("ip","167.205.22.104"));
object.put("server",object.put("port","1234"));
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(miniSock.getOutputStream())));
out.println(object);
out.println();
out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(miniSock.getInputStream()));
response = org.apache.commons.io.IOUtils.toString(in);
in.close();
return response;
}
public String signUp(String username, String passwrd) throws IOException, NoSuchAlgorithmException{
//untuk melakukan signup(Appendix A 2.2)
String response = "";
String request = "";
Socket miniSock = new Socket("167.205.32.46",8025);
MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
byte[] tmp = passwrd.getBytes();
sha1.update(tmp);
JSONObject object = new JSONObject();
object.put("method", "signup");
object.put("username", username);
object.put("password", passwrd);
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(miniSock.getOutputStream())));
out.println(object);
out.println();
out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(miniSock.getInputStream()));
response = org.apache.commons.io.IOUtils.toString(in);
in.close();
return response;
}
public String login(String username, String passwrd) throws IOException, NoSuchAlgorithmException{
//untuk melakukan login(Appendix A 2.3)
String response = "";
String request = "";
Socket miniSock = new Socket("167.205.32.46",8025);
MessageDigest sha1 = MessageDigest.getInstance("SHA-1");
byte[] tmp = passwrd.getBytes();
sha1.update(tmp);
passwrd = byteArrToString(sha1.digest());
// MessageDigest md5 = MessageDigest.getInstance("MD5");
// byte[] tmp = passwrd.getBytes();
// md5.update(tmp);
// passwrd = byteArrToString(md5.digest());
JSONObject object = new JSONObject();
object.put("method", "login");
object.put("username", username);
object.put("password", passwrd);
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(miniSock.getOutputStream())));
out.println(object);
out.println();
out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(miniSock.getInputStream()));
response = org.apache.commons.io.IOUtils.toString(in);
in.close();
return response;
}
public String inventoryInquire(String token) throws IOException, NoSuchAlgorithmException{
//untuk melakukan pengecekan inverntori pemain(Appendix A 2.4)
String response = "";
String request = "";
Socket miniSock = new Socket("167.205.32.46",8025);
JSONObject object = new JSONObject();
object.put("method", "inventory");
object.put("token", token);
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(miniSock.getOutputStream())));
out.println(object);
out.println();
out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(miniSock.getInputStream()));
response = org.apache.commons.io.IOUtils.toString(in);
in.close();
return response;
}
public String mixItem(String token, int item1, int item2) throws IOException, NoSuchAlgorithmException{
//untuk mengkombinasikan item(Appendix A 2.5)
String response = "";
String request = "";
Socket miniSock = new Socket("167.205.32.46",8025);
JSONObject object = new JSONObject();
object.put("method", "mixitem");
object.put("token", token);
object.put("item1", item1);
object.put("item2", item2);
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(miniSock.getOutputStream())));
out.println(object);
out.println();
out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(miniSock.getInputStream()));
response = org.apache.commons.io.IOUtils.toString(in);
in.close();
return response;
}
public String requestMap(String token) throws IOException, NoSuchAlgorithmException{
//untuk merequest map(Appendix A 2.6)
String response = "";
String request = "";
Socket miniSock = new Socket("167.205.32.46",8025);
JSONObject object = new JSONObject();
object.put("method", "map");
object.put("token", token);
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(miniSock.getOutputStream())));
out.println(object);
out.println();
out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(miniSock.getInputStream()));
response = org.apache.commons.io.IOUtils.toString(in);
in.close();
return response;
}
public String movePlayer(String token, int x, int y) throws IOException, NoSuchAlgorithmException{
//untuk move to (x,y)(Appendix A 2.7)
String response = "";
String request = "";
Socket miniSock = new Socket("167.205.32.46",8025);
JSONObject object = new JSONObject();
object.put("method", "move");
object.put("token", token);
object.put("x", x);
object.put("y", y);
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(miniSock.getOutputStream())));
out.println(object);
out.println();
out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(miniSock.getInputStream()));
response = org.apache.commons.io.IOUtils.toString(in);
in.close();
return response;
}
public String getFromField(String token) throws IOException, NoSuchAlgorithmException{
//untuk ambilitem (Appendix A 2.8)
String response = "";
String request = "";
Socket miniSock = new Socket("167.205.32.46",8025);
JSONObject object = new JSONObject();
object.put("method", "field");
object.put("token", token);
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(miniSock.getOutputStream())));
out.println(object);
out.println();
out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(miniSock.getInputStream()));
response = org.apache.commons.io.IOUtils.toString(in);
in.close();
return response;
}
public String offerToMarket(String token, int offered_item, int n1, int demanded_item, int n2) throws IOException, NoSuchAlgorithmException{
//untuk tawarkan item (Appendix A 2.9)
String response = "";
String request = "";
Socket miniSock = new Socket("167.205.32.46",8025);
JSONObject object = new JSONObject();
object.put("method", "offer");
object.put("token", token);
object.put("offered_item", offered_item);
object.put("n1", n1);
object.put("demanded_item", demanded_item);
object.put("n2", n2);
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(miniSock.getOutputStream())));
out.println(object);
out.println();
out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(miniSock.getInputStream()));
response = org.apache.commons.io.IOUtils.toString(in);
in.close();
return response;
}
public String myTradeBox(String token) throws IOException, NoSuchAlgorithmException{
//untuk lihat penawaran sendiri (Appendix A 2.10)
String response = "";
String request = "";
Socket miniSock = new Socket("167.205.32.46",8025);
JSONObject object = new JSONObject();
object.put("method", "tradebox");
object.put("token", token);
PrintWriter out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(miniSock.getOutputStream())));
out.println(object);
out.println();
out.flush();
BufferedReader in = new BufferedReader(new InputStreamReader(miniSock.getInputStream()));
response = org.apache.commons.io.IOUtils.toString(in);
in.close();
return response;
}
private static String byteArrToString (byte[] b){
String res = null;
StringBuffer sb = new StringBuffer(b.length*2);
for (int i = 0; i<b.length;i++){
int j = b[i] & 0xff;
if(j < 16){
sb.append('0');
}
sb.append(Integer.toHexString(j));
}
res = sb.toString();
return res.toLowerCase();
}
}
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package sisterserver;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
/**
*
* @author TOSHIBA
*/
public class SisterServer {
/**
* @param args the command line arguments
*/
static int portNum = 1234;
public static void main(String[] args) throws IOException {
// TODO code application logic here
ServerSocket mainSock;
mainSock = new ServerSocket(portNum);
System.out.println("Listening...");
while(true){
Socket connSocket = mainSock.accept();
if(connSocket!=null){
System.out.println("socket accepted");
Client client = new Client(connSocket);
client.start();
}
}
}
}