Commit 2620ec94 authored by 9731301's avatar 9731301

complete registration

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