Commit 4b6b8970 authored by Timothy Pratama's avatar Timothy Pratama
Browse files

(client) added null input validation for move

parent 4707e8d4
......@@ -331,8 +331,13 @@ public class MainScreen extends javax.swing.JFrame {
private void move_buttonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_move_buttonActionPerformed
String x = x_textfield.getText();
String y = y_textfield.getText();
int pos_x = Integer.parseInt(x);
int pos_y = Integer.parseInt(y);
int pos_x = 0;
int pos_y = 0;
if(x.length() != 0 && y.length() != 0)
{
pos_x = Integer.parseInt(x);
pos_y = Integer.parseInt(y);
}
if(x.length() == 0 || y.length() == 0)
{
JOptionPane.showMessageDialog(this, "x and y value are required");
......@@ -354,6 +359,8 @@ public class MainScreen extends javax.swing.JFrame {
time_detail_label.setText(date_string);
main_character_label.setBounds(start_x + pos_x * panel_width, start_y + pos_y * panel_height, panel_width, panel_height);
position_detail_label.setText("("+x + "," + y +")");
Global.player.setX(String.valueOf(pos_x));
Global.player.setY(String.valueOf(pos_y));
repaint();
}
else
......
......@@ -3,6 +3,7 @@ package elder.tale;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.Random;
......@@ -18,8 +19,8 @@ public class Server {
try
{
int port = 8080;
String username = "Akatsuki";
String password = "LogHorizon";
String username = "username";
String password = "password";
Random rand = new Random(); // untuk random posisi awal player
......@@ -31,10 +32,15 @@ public class Server {
while(true)
{
Socket connectionSocket = serverSocket.accept();
DataInputStream input = new DataInputStream(connectionSocket.getInputStream());
InputStream input = connectionSocket.getInputStream();
DataOutputStream output = new DataOutputStream(connectionSocket.getOutputStream());
String client_message = input.readUTF();
byte[] client_bytes = new byte[4096];
int count = input.read(client_bytes);
String client_message = new String(client_bytes);
client_message = client_message.substring(0, count);
System.out.println("client_message: " + client_message);
JSONParser parser = new JSONParser();
JSONObject client_json = (JSONObject) parser.parse(client_message);
......@@ -277,7 +283,7 @@ public class Server {
}
System.out.println("response: " + response);
output.writeUTF(response.toString());
output.write(response.toString().getBytes());
}
}
catch (IOException | ParseException ex)
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment