Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
41 commits
Select commit Hold shift + click to select a range
f09a779
i made some changes
himeii Oct 28, 2015
30e2948
Test commit
EvGe22 Oct 28, 2015
b0a1849
Started something
himeii Oct 31, 2015
96521bb
Started something
himeii Oct 31, 2015
a27a90d
Useless commit I have to do because Git tells me to D:
EvGe22 Oct 31, 2015
6969709
Rewrote everything from scratch :3
EvGe22 Nov 5, 2015
d3e93af
Create iteration1.1
NotHappyDyadik Nov 8, 2015
7330d9a
Added empty Caller class and fixed the other ones
EvGe22 Nov 12, 2015
a84b1d4
начал писать Caller + CallListener, Илья - правь
himeii Nov 15, 2015
df27624
начал писать Caller + CallListener, Илья - правь
himeii Nov 15, 2015
d422423
I don't know what is this D:
EvGe22 Nov 18, 2015
adec4cf
TOO LATE, U KNOW?
EvGe22 Nov 18, 2015
af7ad1b
I DON'T KNOW
himeii Nov 18, 2015
b14228b
MainGui
NotHappyDyadik Nov 18, 2015
5e938a6
wip
EvGe22 Nov 18, 2015
8e09739
LFrame
NotHappyDyadik Nov 18, 2015
d5e43f8
Merge branch 'master' of http://github.com/EvGe22/ChatApp
EvGe22 Nov 18, 2015
28cb790
Kostiliiiii
EvGe22 Nov 18, 2015
13e35c0
Work maybe?
EvGe22 Nov 18, 2015
2f28afe
Fixed some bugs, added some new ones :3
EvGe22 Nov 24, 2015
49b85c4
wip I guess
EvGe22 Nov 25, 2015
e7241be
Still fixing stuff. Some bugs should be fixed now, hopefully.
EvGe22 Dec 1, 2015
d1235c8
+1 bugfix
EvGe22 Dec 1, 2015
e91216d
wip again.
EvGe22 Dec 2, 2015
2897ea6
wip again.
EvGe22 Dec 2, 2015
1858272
SERVER CONNECTION
EvGe22 Dec 2, 2015
bcc7fc5
Create LFrame
NotHappyDyadik Dec 3, 2015
84e5448
wip once again
EvGe22 Dec 9, 2015
d8326e7
Merge branch 'master' of http://github.com/EvGe22/ChatApp
EvGe22 Dec 9, 2015
06a1dd0
I DON'T KNOW
himeii Dec 9, 2015
1ee6b98
Well, I still don't know how to do a jar with mySQL driver in it, so …
EvGe22 Dec 9, 2015
9ca4058
Last one
EvGe22 Dec 9, 2015
de3009c
Update MainGUI.java
NotHappyDyadik Dec 10, 2015
e4a23b5
wip, changing a lot of stuff
EvGe22 Dec 16, 2015
9990cb1
still wip
EvGe22 Dec 18, 2015
71fbee2
Starting to connect with the server
EvGe22 Dec 19, 2015
9c15b37
Continuing to connect with the server
EvGe22 Dec 20, 2015
c9151cd
Working on contacts
EvGe22 Dec 21, 2015
5015d1c
Working on contacts
EvGe22 Dec 22, 2015
d99902a
Working on contacts
EvGe22 Dec 23, 2015
7558a24
fixing
EvGe22 Dec 27, 2015
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions src/CallCommand.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
public class CallCommand extends Command {

String nick;

public CallCommand(){
super(CommandType.CALL);
}

public CallCommand(String nick) {
super(CommandType.CALL);
this.nick = nick;
}

public String getNick() {
return nick;
}
}
46 changes: 46 additions & 0 deletions src/CallListener.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
import java.io.IOException;
import java.net.InetAddress;
import java.net.ServerSocket;
import java.net.Socket;

public class CallListener {
private String localNick,remoteNick;
private boolean isBusy,isOnline;
private String remoteIP;
private int remotePort;
private ServerSocket serverSocket;
private Command lastCommand;
private NickCommand nickCommand;

public CallListener(String localNick){
try {
serverSocket = new ServerSocket(Protocol.PORT_NUMBER);
} catch (IOException e) {
//asd
}
this.localNick=localNick;
this.isBusy= false;
this.isOnline=true;
}

public Connection getConnection() throws IOException {
Connection connection = new Connection(serverSocket.accept());
return connection;
}

public void setBusy(boolean isBusy) {
this.isBusy = isBusy;
}

public void setNick(String nick){
localNick=nick;
}

public String getRemoteNick(){
return remoteNick;
}

public void setOnline(Boolean online){
isOnline=online;
}
}
62 changes: 62 additions & 0 deletions src/CallListenerThread.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
import java.io.IOException;

public class CallListenerThread {
/*

private String localNick;
private CallListener callListener;
private boolean stop;
private String remoteNick;
private Connection remoteConnection;
private IncomingCallForm form;




public CallListenerThread(String localNick,Boolean isBusy){
callListener = new CallListener(localNick);

}

public void run() {
try {
while (!stop) {

remoteConnection = callListener.getConnection();
if (remoteConnection == null) continue;
remoteNick=callListener.getRemoteNick();
form = new IncomingCallForm(remoteConnection,remoteNick);
System.out.println("AZAZA");

}
}
catch(IOException e){
e.printStackTrace();
}


}


public Connection getRemoteConnection(){
return remoteConnection;
}

public void setBusy(Boolean isBusy){
callListener.setBusy(isBusy);
}

public void setOnline(Boolean online){
callListener.setOnline(online);
}

public void setNick(String nick){
localNick=nick;
callListener.setNick(localNick);
}


public void kill() {
stop = true;
}*/
}
63 changes: 63 additions & 0 deletions src/Caller.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import java.io.IOException;
import java.net.Socket;

public class Caller {
private String localNick;
private String remoteIP;
private String remoteNick;
private Command lastCommand;
private NickCommand nickCommand;
private String lastError;


public Caller(String localNick,String remoteIP){
this.localNick=localNick;
this.remoteIP=remoteIP;

}

public Connection call() throws IOException {
Connection connection = new Connection(new Socket(remoteIP,Protocol.PORT_NUMBER));
//Проверка, к тому ли мы подключились.
lastCommand = connection.recieve();
if (lastCommand.type==CommandType.NICK) {
nickCommand = (NickCommand) lastCommand;
}
else{
connection.disconnect();
lastError="Wrong IP";
UltimateGUI ultimateGUI = new UltimateGUI("Failed to connect");
return null;
}

//Проверка, занят ли тот пользователь
remoteNick = nickCommand.getNick();
if (nickCommand.isBusy()){
lastCommand = connection.recieve();
connection.disconnect();
UltimateGUI busyGUI = new UltimateGUI(remoteNick+" is busy");
lastError="User is busy";
remoteNick=null;

return null;
}

//Если не занят, то отсылаем ник и ждём подтверждения

lastCommand = connection.recieve();

//Если accept - вернуть connection
if (lastCommand.type==CommandType.ACCEPT) return connection;
else{
UltimateGUI ultimateGUI = new UltimateGUI(remoteNick+" rejected your call");
lastError="User rejected your call";

connection.disconnect();
return null;
}

}
public String getRemoteNick(){
return remoteNick;
}
}
10 changes: 10 additions & 0 deletions src/Colors.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import java.awt.*;

public class Colors {
public static final Color mainGreen = new Color(139, 194, 73);
public static final Color darkGreen = new Color(54, 107, 52);
public static final Color midGreen = new Color(103, 159, 66);
public static final Color softGreen = new Color(242, 248, 233);
public static final Color darkGrey = new Color(67, 67, 67);
public static final Color lightGreen = new Color(0xDCECC8);
}
75 changes: 75 additions & 0 deletions src/Command.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
import java.util.ArrayList;
import java.util.Scanner;

public class Command {
protected CommandType type ;

public Command(){}

public Command(CommandType type){
this.type=type;
}

public static Command getCommand(Scanner in){
String string ="";
if (in.hasNextLine()) {
string = in.nextLine();
}
else{
return null;
}
if (string.startsWith(Protocol.ACCEPTED)) return new Command(CommandType.ACCEPT);
if (string.startsWith(Protocol.DISCONNECT)) return new Command(CommandType.DISCONNECT);
if (string.startsWith(Protocol.REJECTED)) return new Command(CommandType.REJECT);
if (string.startsWith(Protocol.GREETING)) return new NickCommand(string);
if (string.startsWith(Protocol.MESSAGE)) return new MessageCommand(Protocol.decode(in.nextLine()));
if (string.startsWith(Protocol.HELLO_SERVER)) return new Command(CommandType.HELLO_SERVER);
if (string.startsWith(Protocol.HELLO_CLIENT)) return new Command(CommandType.HELLO_CLIENT);

if (string.startsWith(Protocol.CONTACTS)){
string = string.replace(Protocol.CONTACTS+" ","");
ArrayList<Contact> result = new ArrayList<Contact>();
String[] tmp = string.split(" ");
for (int i=0;i<tmp.length;i+=2){
Contact contact = new Contact(null,tmp[i]);
contact.setOnline(Boolean.parseBoolean(tmp[i+1]));
result.add(contact);
}
return new ContactsCommand(result);
}

if (string.startsWith(Protocol.MY_CONTACTS)){
string = string.replace(Protocol.MY_CONTACTS+" ","");
ArrayList<Contact> result = new ArrayList<Contact>();
String[] tmp = string.split(" ");
for (int i=0;i<tmp.length;i+=3){
Contact contact = new Contact(null,tmp[i]);
contact.setFav(Boolean.parseBoolean(tmp[i+1]));
contact.setOnline(Boolean.parseBoolean(tmp[i + 2]));
result.add(contact);
}
return new MyContactsCommand(result);
}

if (string.startsWith(Protocol.BUSY)) return new Command(CommandType.BUSY);
if (string.startsWith(Protocol.OFFLINE)) return new Command(CommandType.OFFLINE);
if (string.startsWith(Protocol.EMPTYCONTACTS)) return new Command(CommandType.EMPTYCONTACTS);
if (string.startsWith(Protocol.EMPTYMYCONTACTS)) return new Command(CommandType.EMPTYMYCONTACTS);
if (string.startsWith(Protocol.CALL)) return new CallCommand(string.replace(Protocol.CALL+" ",""));
if (string.startsWith(Protocol.DISCONNECT_FROM_USER)) return new Command(CommandType.DISCONNECT_FROM_USER);
if (string.startsWith(Protocol.ONLINE_CONTACTS)) {
string = string.replace(Protocol.ONLINE_CONTACTS+" ","");
String[] tmp = string.split(" ");
ArrayList<Boolean> onlines = new ArrayList<Boolean>();
for (String s : tmp){
onlines.add(Boolean.parseBoolean(s));
}
return new OnlineCommand(onlines);
}
if (string.startsWith(Protocol.LOGOUT)) return new Command(CommandType.LOGOUT);

return null;
}

}

4 changes: 4 additions & 0 deletions src/CommandType.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
public enum CommandType {
ACCEPT, REJECT, DISCONNECT, NICK, MESSAGE, HELLO_SERVER, HELLO_CLIENT, CALL, LOGIN, SIGNUP, DISCONNECT_FROM_USER,
CONTACTS, CONTACT, ONLINE_CONTACTS, LOGOUT, EMPTYCONTACTS, EMPTYMYCONTACTS, GET_CONTACTS, BUSY, OFFLINE, MY_CONTACTS, GET_MY_CONTACTS
}
Loading