Commit 2620ec94 authored by 9731301's avatar 9731301

complete registration

parent ffeb34ac
......@@ -2,18 +2,18 @@
<project version="4">
<component name="ChangeListManager">
<list default="true" id="0b3d586d-9f0f-4ca4-b09d-03a200e1e684" name="Default Changelist" comment="">
<change afterPath="$PROJECT_DIR$/src/UI/GameState/RewardState.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/.idea/workspace.xml" beforeDir="false" afterPath="$PROJECT_DIR$/.idea/workspace.xml" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/GameState/RewarsState.class" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/Game/GameFrame.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/Game/GameFrame.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/Game/GameLoop.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/Game/GameLoop.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/Game/Rendering.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/Game/Rendering.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/GameState/RewarsState.java" beforeDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/GameState/TankState.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameState/TankState.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/GameState/WallState.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/GameState/WallState.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/LogIn/Game/GameFrame.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/Game/GameFrame.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/LogIn/Game/GameLoop.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/Game/GameLoop.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/LogIn/Game/Rendering.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/Game/Rendering.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/Server_Client/Client.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/Server_Client/Client.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/Server_Client/Server.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/Server_Client/Server.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/Server_Client/registeredName/registeredList" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/Server_Client/registeredName/registeredList" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/Main.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/LogIn/Main.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/Registration/InitialPanel$3.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/Registration/InitialPanel$3.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/out/production/JTankTrouble/UI/Registration/InitialPanel.class" beforeDir="false" afterPath="$PROJECT_DIR$/out/production/JTankTrouble/UI/Registration/InitialPanel.class" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Server_Client/Client.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Server_Client/Client.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Server_Client/Server.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/Server_Client/Server.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/Server_Client/registeredName/registeredList" beforeDir="false" afterPath="$PROJECT_DIR$/src/Server_Client/registeredName/registeredList" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/LogIn/Main.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/LogIn/Main.java" afterDir="false" />
<change beforePath="$PROJECT_DIR$/src/UI/Registration/InitialPanel.java" beforeDir="false" afterPath="$PROJECT_DIR$/src/UI/Registration/InitialPanel.java" afterDir="false" />
</list>
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
......@@ -138,7 +138,8 @@
<workItem from="1596265047938" duration="12842000" />
<workItem from="1596295633892" duration="19181000" />
<workItem from="1596360744874" duration="14702000" />
<workItem from="1596382833689" duration="15516000" />
<workItem from="1596382833689" duration="23785000" />
<workItem from="1596407579858" duration="9000" />
</task>
<servers />
</component>
......@@ -146,14 +147,14 @@
<option name="version" value="1" />
</component>
<component name="WindowStateProjectService">
<state x="517" y="216" key="#com.intellij.fileTypes.FileTypeChooser" timestamp="1595580808418">
<state x="517" y="216" key="#com.intellij.fileTypes.FileTypeChooser" timestamp="1596402386433">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="517" y="216" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1536.824@0.0.1536.824" timestamp="1595580808418" />
<state x="574" y="122" key="#com.intellij.ide.util.MemberChooser" timestamp="1596386941582">
<state x="517" y="216" key="#com.intellij.fileTypes.FileTypeChooser/0.0.1536.824@0.0.1536.824" timestamp="1596402386433" />
<state x="574" y="122" key="#com.intellij.ide.util.MemberChooser" timestamp="1596406076120">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="574" y="122" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1596386941582" />
<state x="574" y="122" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1596406076120" />
<state x="566" y="298" width="403" height="237" key="#com.intellij.refactoring.move.moveClassesOrPackages.MoveClassesOrPackagesDialog.classes" timestamp="1596368712645">
<screen x="0" y="0" width="1536" height="824" />
</state>
......@@ -166,30 +167,34 @@
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="593" y="0" key="CommitChangelistDialog2/0.0.1536.824@0.0.1536.824" timestamp="1595639194593" />
<state width="1493" height="201" key="GridCell.Tab.0.bottom" timestamp="1596399005739">
<state width="1493" height="201" key="GridCell.Tab.0.bottom" timestamp="1596407509883">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="201" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1596399005739" />
<state width="1493" height="201" key="GridCell.Tab.0.center" timestamp="1596399005739">
<state width="1493" height="201" key="GridCell.Tab.0.bottom/0.0.1536.824@0.0.1536.824" timestamp="1596407509883" />
<state width="1493" height="201" key="GridCell.Tab.0.center" timestamp="1596407509883">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="201" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1596399005739" />
<state width="1493" height="201" key="GridCell.Tab.0.left" timestamp="1596399005739">
<state width="1493" height="201" key="GridCell.Tab.0.center/0.0.1536.824@0.0.1536.824" timestamp="1596407509883" />
<state width="1493" height="201" key="GridCell.Tab.0.left" timestamp="1596407509883">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="201" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1596399005739" />
<state width="1493" height="201" key="GridCell.Tab.0.right" timestamp="1596399005739">
<state width="1493" height="201" key="GridCell.Tab.0.left/0.0.1536.824@0.0.1536.824" timestamp="1596407509883" />
<state width="1493" height="201" key="GridCell.Tab.0.right" timestamp="1596407509883">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state width="1493" height="201" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1596399005739" />
<state width="1493" height="201" key="GridCell.Tab.0.right/0.0.1536.824@0.0.1536.824" timestamp="1596407509883" />
<state x="589" y="114" key="RollbackChangesDialog" timestamp="1595702094731">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="589" y="114" key="RollbackChangesDialog/0.0.1536.824@0.0.1536.824" timestamp="1595702094731" />
<state x="107" y="201" key="com.intellij.ide.util.TipDialog" timestamp="1596360806638">
<state x="107" y="201" key="com.intellij.ide.util.TipDialog" timestamp="1596407580390">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="107" y="201" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1596360806638" />
<state x="107" y="201" key="com.intellij.ide.util.TipDialog/0.0.1536.824@0.0.1536.824" timestamp="1596407580390" />
<state x="578" y="330" key="com.intellij.openapi.vcs.update.UpdateOrStatusOptionsDialogupdate-v2" timestamp="1596406077996">
<screen x="0" y="0" width="1536" height="824" />
</state>
<state x="578" y="330" key="com.intellij.openapi.vcs.update.UpdateOrStatusOptionsDialogupdate-v2/0.0.1536.824@0.0.1536.824" timestamp="1596406077996" />
<state x="499" y="179" key="extract.method.dialog" timestamp="1596369268790">
<screen x="0" y="0" width="1536" height="824" />
</state>
......
......@@ -3,6 +3,7 @@ package Server_Client;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.net.InetAddress;
import java.net.Socket;
......@@ -10,14 +11,15 @@ public class Client {
private String user_pass;
public Client(String username, String password) {
user_pass = username + password;
user_pass = username.trim() +"|"+ password.trim();
}
public void run(){
System.out.println("client connected");
try (Socket client = new Socket(InetAddress.getLocalHost().getHostName(),5757)){
OutputStream out = client.getOutputStream();
byte[] buffer = new byte[2048];
out.write(user_pass.getBytes());
PrintWriter writer = new PrintWriter(out,true);
writer.println(user_pass);
} catch (IOException e) {
e.printStackTrace();
}
......
......@@ -2,42 +2,78 @@ package Server_Client;
import java.io.*;
import java.net.ServerSocket;
import java.net.Socket;
import java.nio.charset.Charset;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.List;
public class Server {
private File registeredList = createAFile();
static ServerSocket serverSocket=null;
public Server() throws IOException {
runRegistration();
}
/**
*
* @return
*/
public File runRegistration() throws IOException {
ServerSocket serverSocket = new ServerSocket(5757);
try (Socket connectionSocket = serverSocket.accept()){
System.out.println("new client connected");
OutputStream out = connectionSocket.getOutputStream();
InputStream in = connectionSocket.getInputStream();
byte[] buffer = new byte[2048];
int read = in.read(buffer);
public void runRegistration() {
if (serverSocket!=null) return;
try {
serverSocket = new ServerSocket(5757);
System.out.println("server connected");
} catch (IOException e) {
e.printStackTrace();
}
}
public boolean waitForClient() throws IOException {
boolean s = false;
while (true) {
Socket connectionSocket = serverSocket.accept();
System.out.println("new client connected");
OutputStream out = connectionSocket.getOutputStream();
InputStream in = connectionSocket.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(in));
String line = reader.readLine();
System.out.println(line.split("\\|")[0]);
s = !pass_userNameIsAvailable(line.split("\\|")[0]);
if (s) {
String file = new String(Files.readAllBytes(Paths.get(registeredList.toURI())), StandardCharsets.UTF_8);
FileOutputStream fileWriter = new FileOutputStream(registeredList);
fileWriter.write(read);
PrintStream ps = new PrintStream(fileWriter);
ps.println(file);
ps.println(line);
}
break;
}
return null;
return s;
}
/**
*
* @param password
* @param username
* @return
* @throws IOException
*/
public boolean pass_userNameIsAvailable(String password , String username) throws IOException {
String pass_userName = password+username;
if (readFile().contains(pass_userName)){
return true;
public boolean pass_userNameIsAvailable( String username) throws IOException {
for (String line : readFile()){
if (line.trim().isEmpty()) continue;
System.out.println(line);
if (line.split("\\|")[0].equalsIgnoreCase(username.trim())) return true;
}
return false;
}
public boolean pass_userNameIsAvailable( String pass,String username) throws IOException {
for (String line : readFile()){
if (line.split("\\|")[0].equalsIgnoreCase(username.trim()) &&
line.split("\\|")[1].equals(pass.trim())) return true;
}
return false;
}
......@@ -47,14 +83,8 @@ public class Server {
* @return
* @throws IOException
*/
private String readFile() throws IOException {
String fileContent = "";
FileInputStream read = new FileInputStream(registeredList);
int c;
while ((c = read.read()) != -1){
fileContent += new Character((char)c).toString();
}
return fileContent;
private List<String> readFile() throws IOException {
return Files.readAllLines(Paths.get(registeredList.toURI()));
}
/**
......@@ -62,8 +92,9 @@ public class Server {
* @return
*/
public File createAFile() throws IOException {
File registeredList = null;
try {
File registeredList = new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\src\\Server_Client\\registeredName\\registeredList");
registeredList = new File("C:\\Users\\Lenovo\\IdeaProjects\\JTankTrouble\\src\\Server_Client\\registeredName\\registeredList");
if (registeredList.createNewFile()) {
System.out.println("File created: " + registeredList.getName());
} else {
......@@ -73,6 +104,6 @@ public class Server {
System.out.println("An error occurred.");
e.printStackTrace();
}
return runRegistration();
return registeredList;
}
}
\ No newline at end of file
package UI.LogIn;
/*** In The Name of Allah ***/
import UI.Registration.InitialFrame;
import java.io.IOException;
/**
......@@ -12,12 +14,12 @@ public class Main {
public static void main(String[] args) throws IOException {
// Show the game menu ...
// InitialFrame initialFrame = new InitialFrame("Trouble Tank");
// if (initialFrame.isClickOnPlay()) {
InitialFrame initialFrame = new InitialFrame("Trouble Tank");
if (initialFrame.isClickOnPlay()) {
// After the player clicks 'PLAY' ...
MainFrame mainframe = new MainFrame("Trouble Tank");
// }
}
}
}
......@@ -102,6 +102,8 @@ public class InitialPanel extends JPanel {
fieldsPanel.add(emailField);
regPanel.add(fieldsPanel);
regPanel.add(saveBtn);
saveBtn.addMouseListener(new MouseAdapter() {
@Override
public void mouseClicked(MouseEvent e) {
......@@ -113,13 +115,22 @@ public class InitialPanel extends JPanel {
JOptionPane.showMessageDialog(saveBtn,"password and repetition are not equal");
}
else {
try {
Server server = new Server();
System.out.println("loading");
Client newClient = new Client(usernameField.getText() , passwordField.getText() );
newClient.run();
boolean s = server.waitForClient();
if (s){
JOptionPane.showMessageDialog(saveBtn,"done");
}else{
JOptionPane.showMessageDialog(saveBtn,"username already exists");
}
} catch (IOException ex) {
ex.printStackTrace();
}
Client newClient = new Client(usernameField.getText() , passwordField.getText() );
newClient.run();
}
}
});
......
Markdown is supported
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