Gamers' Lounge :  forum
Arrange meeting times for new games, discuss past games and strategies, socialize with other players. 
Pages: Previous123Next
Current Page: 2 of 3
Re: A new project
Posted by: Paars ()
Date: September 23, 2010 02:59PM

----------------
Actually skip that, it doesnt have to be rewritten at all, now here's some luck I don't have very often. ;). Just need slightly clearning up of unused parts is all and perhaps some commentary for people that would want to know whats going on.
I ll post the classes here, tho I don't expecty everyone or anyone to understand it. I will give a description for each class so you know how far we stand.

The next 5 classes are divided into 2 things, There is the Main class for the server which uses only the 2 other classes, SocketServer and the MultpleLogin Class. And there is Main2 class together with the SocketClient class, this is only needed for the client/players(tho in future a seperate stripped SocketServer class will be created for the players, so they can host themselves a game over ip, for when the real server is out.)
Here goes.


----------------------------------------------------------

Main class, this class is the very first class to be run by the server, if it ain't running nothing else will.
There's a lot of useless coding in this class such as showing a frame with some textarea's but are still unused and probably will stay like that.
All it does is create an object of the socketserver and it continuesly is waiting for clients to connect,if so it creates a new object of MultipleLoginclass adds the playercount then goes back to waiting for new connections again.

------------------------------------------------------------

import javax.swing.*;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import java.net.Socket;
import java.net.ServerSocket;
import java.util.Vector;

public class Main implements KeyListener, Runnable
{

public static int players=0,playersOnline=0;
public static int chatIndexRemoval=0;
private JFrame jf = new JFrame();
private JTextArea jtaChat = new JTextArea(), jtaPeopleOnline = new JTextArea();
private JTextField jtfChatBar = new JTextField();
SocketServer socketServer;
String input;
public String output;
int whatever =0;
public static Vector chatVector = new Vector();
public static Vector peopleOnline = new Vector();
public Main()
{
jf.setTitle("Main Frame");
jf.setBounds(100,100,800,800);
jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
jf.setLayout(null);
jtaChat.setBounds(10,10,500,700);
jtaPeopleOnline.setBounds(600,10,250,700);
jtfChatBar.setBounds(10,725, 700,25);
jtfChatBar.addKeyListener(this);

jf.add(jtfChatBar);
jf.add(jtaPeopleOnline);
jf.add(jtaChat);
jf.setVisible(true);

socketServer = new SocketServer();
new Thread(this).start();


}


public static void main(String[]args)
{
new Main();
}

public void keyTyped(KeyEvent e) {
//To change body of implemented methods use File | Settings | File Templates.
}

public void keyPressed(KeyEvent e) {
//To change body of implemented methods use File | Settings | File Templates.
}


public void keyReleased(KeyEvent e)
{
if(e.getSource() == jtfChatBar)
{
if(e.getKeyCode() == KeyEvent.VK_ENTER)
{
// socketServer.sendData("Server: "+jtfChatBar.getText());
output = "Server: "+jtfChatBar.getText();
jtaChat.append("Server:" +jtfChatBar.getText() + "\n");
jtfChatBar.setText("");
}
}
}

public void run()
{
while(true)
{
new MultipleLoginsClass(socketServer.getData());
players++;
System.out.println("new Socket Made");
}
}

public static void removeFromPlayersVector(String s)
{
for(int i=0; i < peopleOnline.capacity();i++)
{
try
{
if(s.equals(peopleOnline.get(i)))
{
peopleOnline.remove(i);
System.out.println("Player removed");

}
}
catch(Exception e)
{}
}
}
}

------------------------------------------------------------

SocketServer Class this is just the basic class for the socketServer, an object of this class is created in Main, when created, it Starts up a server with a PortNumber whichever I give it. then it waits for a single client to connect.(May seem a bit weird considering Main does the same, but Main uses another class so more then 1 clients/players can connect.

------------------------------------------------------------

import java.net.*;
import java.io.*;

public class SocketServer
{
ServerSocket socketServer;
Socket clientSocket;
public SocketServer()
{
try
{
socketServer = new ServerSocket(1987);
}
catch(IOException e)
{
System.out.println("Error" + e.getMessage());
System.exit(-1);
}
}
public Socket getData()
{
try
{
clientSocket = socketServer.accept();
}
catch (IOException e)
{
System.err.println("Accept failed.");
System.exit(1);
}

return clientSocket;
}
}

------------------------------------------------------------

MultipleLoginClass This class is actually 2 classes, I nested one inside the MultipleLoginClass can't remember why lol. Still, I'm very glad I found this class cuz it was a bitch to write before I got it right. It uses multiple Threads, which means more then 1 proces is running at a time. Always becarefull With keeping it synchronized right, else it will fail horribly.
This class allows for more clients to connect to the server.
Its continuesly listening for Information given by the client, if this info doesn't start with login:name then it will add the information received to a ChatTextVector(Which makes me think now, I need to secure this before people start typing login:name in lobby fucking stuff up lol.) Also, diffrent information is going to be send over these sockets, game info etc etc. all connections will run through this vector, sending the information to his client until they are done.

So basicly, this class makes sure all information received from each client, will be send to all other clients.


------------------------------------------------------------

import java.net.Socket;
import java.io.PrintWriter;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Vector;

public class MultipleLoginsClass implements Runnable
{
boolean quit =false;
Socket s;
String input, name;
Vector myInput = new Vector();
PrintWriter out;
BufferedReader in;
int playerOnline=0;
public MultipleLoginsClass(Socket s)
{
this.s=s;
try
{
out = new PrintWriter(s.getOutputStream(),true);
}
catch(IOException e)
{
System.out.println(e.getMessage());
System.exit(1);
}
try
{
in = new BufferedReader(new InputStreamReader(s.getInputStream()));
}
catch(IOException e)
{

}
new Thread(new VectorDealing()).start();
new Thread(this).start();
}
public void listenSocket()
{

try
{
while((input = in.readLine())!=null)
{

if(!getLogin(input))
{
Main.chatVector.add(input);
}

}

}
catch(IOException e)
{
System.out.println("exiting this socket");
Main.chatVector.add(name + " logged off");
Main.removeFromPlayersVector(name);
Main.playersOnline --;
quit = true;

}
}
public void run()
{

while(!quit)
{
listenSocket();
}

}

public class VectorDealing implements Runnable
{
Thread t = new Thread();
int index=0;

public VectorDealing()
{
// t.start();

}
public void run()
{
// boolean quit=false;
while(!quit)
{
try
{
if(Main.chatVector.elementAt(index) != null)
{
out.println(Main.chatVector.elementAt(index));
Main.chatIndexRemoval++;
index++;
}
}
catch(Exception e)
{}
if(playerOnline != Main.playersOnline)
{
playerOnline = Main.playersOnline;
out.println("login:"+Main.peopleOnline);
}
}
}
}


public boolean getLogin(String s)
{
String[] loginString = s.split(":");
{
if(loginString[0].equals("login"))
{
Main.peopleOnline.add(loginString[1]);
Main.playersOnline++;
name = loginString[1];
return true;
}

}
return false;
}
}


------------------------------------------------------------

Main2 this is the Runnable exe for the Client/player, It tries to connect to the server over a given ip(locally also possible with pc name).


Main2 builds up a loginFrame, for now(no database yet)you can login pretty much with any name as long its not empty. As soon you hit the login button, it builds up a SocketClient Object with some basic function for receiving and sending data to his serverconnection, if this connectiontion is established, your frame will be edited to a lobby frame. Your login actually now will be send.

From here, the client will send information to the server when pressed enter on chatbar. And it has a continuesly running proces waiting from information from the server. It checks if its a login, if so it will show it on the right side in the players list, if not. It will show the info on the chat Screen.

------------------------------------------------------------
import javax.swing.*;
import java.awt.event.KeyListener;
import java.awt.event.KeyEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseEvent;
import java.io.IOException;

public class Main2 implements KeyListener, MouseListener, Runnable
{

JFrame jf = new JFrame();
JTextArea jtaLoginName = new JTextArea(),jtaChat = new JTextArea(), jtaPeopleOnline=new JTextArea();
JTextField jtfChatBar = new JTextField();
JButton jbLogin = new JButton("login");
SocketClient socketClient;
String name,input;
Thread myThread = new Thread();
JScrollPane gag;

public Main2()
{
jf.setTitle("Main Frame2");
jf.setBounds(250,200,400,400);
jf.setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
jf.setLayout(null);
jtaLoginName.setBounds(100,100,200,30);
jbLogin.setBounds(125,150,100,30);
jbLogin.addMouseListener(this);
jtfChatBar.setBounds(50,700,700,30);
jtaChat.setBounds(10,10,500,650);
jtaChat.setLineWrap(true);
jtaChat.setEditable(false);
jtaChat.setCaretPosition(0);
jtaChat.setWrapStyleWord(true);
jtaPeopleOnline.setBounds(550,10,200,650);
jtaPeopleOnline.setEditable(false);
gag = new JScrollPane(jtaChat);
gag.setBounds(jtaChat.getBounds());
jtfChatBar.addKeyListener(this);
jf.add(jbLogin);
jf.add(jtaLoginName);
jf.add(jtaPeopleOnline);
jf.setVisible(true);

}

public void keyTyped(KeyEvent e)
{

}

public void keyPressed(KeyEvent e)
{
//To change body of implemented methods use File | Settings | File Templates.
}

public void keyReleased(KeyEvent e)
{
if(e.getSource() == jtfChatBar)
{
if(e.getKeyCode() == KeyEvent.VK_ENTER)
{
if(jtfChatBar.getText() !="")
{
socketClient.sendData(name+": "+jtfChatBar.getText());
jtfChatBar.setText("");
}
}
}
}

public static void main(String[]args)
{
new Main2();
}

public void mouseClicked(MouseEvent e)
{
if(e.getSource()==jbLogin)
{
if(!jtaLoginName.getText().equals(""))
{
socketClient = new SocketClient("192.168.1.100");
jf.setBounds(100,100,800,800);
jf.add(jtfChatBar);
jtaLoginName.setVisible(false);
jbLogin.setVisible(false);
jf.add(gag);
socketClient.sendData("login:"+jtaLoginName.getText());
socketClient.sendData(jtaLoginName.getText() + " logged in.");
name = jtaLoginName.getText();
new Thread(this).start();
}
}
}

public void mousePressed(MouseEvent e)
{
//To change body of implemented methods use File | Settings | File Templates.
}

public void mouseReleased(MouseEvent e)
{
//To change body of implemented methods use File | Settings | File Templates.
}

public void mouseEntered(MouseEvent e)
{
//To change body of implemented methods use File | Settings | File Templates.
}

public void mouseExited(MouseEvent e)
{
//To change body of implemented methods use File | Settings | File Templates.
}



public void listenSocket()
{
if(socketClient != null)
{
try
{
while((input = socketClient.in.readLine())!=null)
{
if(!getLogin(input))
{
jtaChat.append(input+"\n");

}
else
{
jtaPeopleOnline.setText("");

String[] loggedOnPeople = getLoginAppend(input);
for(int i=0; i < loggedOnPeople.length;i++)
{
jtaPeopleOnline.append(loggedOnPeople +"\n");
}
}

}
}
catch(IOException e)
{
System.out.println("Error");
System.exit(1);
}

}
}

public void run()
{
while(true)
{
listenSocket();
}
}
public boolean getLogin(String s)
{
String[] loginString = s.split(":");
{
if(loginString[0].equals("login"))
{
return true;
}

}
return false;
}

public String[] getLoginAppend(String s)
{
String[] myString = s.split(":");
String[] MyString2 = myString[1].split(",");
return MyString2;
}
}




------------------------------------------------------------


SocketClient Class when an object of this class is created in the Main file, it establishes connection when possible(Over a given port). and then functions to receive and send are added.

------------------------------------------------------------

import java.net.*;
import java.io.*;

public class SocketClient
{

Socket socket;
PrintWriter out;
BufferedReader in, stdIn;
String test;

public SocketClient(String s)
{
try
{
socket = new Socket(s,1987);
out = new PrintWriter(socket.getOutputStream(),true);
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
System.out.println("Connection established");
}
catch(UnknownHostException e)
{
System.out.println("Error: " +e.getMessage());
System.exit(1);
}
catch (IOException e)
{
System.err.println("Couldn't get I/O for the connection to: paars .");
System.exit(1);
}

}
public void sendData(String s)
{
out.println(s);
}


}

------------------------------------------------------------------


So these are the classes that make it possible to login with a name and chat with the other clients, players. But they will be used more For sending lots of other information. Like game information and such as soldiers of a country attacking another or which country belongs to who etc etc.

After reading through the coding etc, I realize I do need to clean it up a bit.

On the client screen, a Create, join etc buttons are still needed. Small thing to do. I will also put on a checkbox with Autoscroll on/off.Conquerorgame or msn, all keep scrolling down, which makes sense cuz else it never would. But sometimes you need to look up some previously data, this way you can.
Little bit of work there.

What still needs to be done is quite a lot, I'm realizing. I was planning on settup my apache server better with a mysql database system and a database for registering, logging in + to check if ur a player a mod or admin. But I better probably do this later cuz it isn't nessecary yet before I have an actually working game.(I already have written working classes in Java itself tho to connect to database and retrieve information.)

The ai still needs to be created/thought off. But still hoping for Acro to do this + its not a first priority before I can get the game working for players first.

Some Frame work around the lobby system still needs to be done with information, this is a prioraty, such as gameName popup screen when creata, listing/showing the games created + an option screen(Which is not right away priority), However the amount of players and which capitals it are going to be I can use the exact codeworks I used for the Capital choser which I posted in another topic for ConquerorGame.

Images/Map building, this I can't tell how long it ll take. I already have created some working classes to place images on. You even can select these images(countries). But there's a square around them, need to find out how this .png style is not show nor should it be able to selected.
Filling up countries, not completely sure on how doing this yet but I ll find out fast enough. I wondered how Conquerorgame still shows the country background + color but its an easy answer. I just have to use opacity/transparancy.

Now I do need someone badly to get me all the countries as individual image files(Probably.png)But I will get back to you on that, if not then consider I just need .png files.
Now I will look in my programming environment if there's a possible option for me to drag and drop images to a frame.If not, the positioning is going to be a bitch just takes long, not hard(That's what she said!) Oh man I'm good. Anyway I will start working on getting some testings to work, hopefully someone can get me the image files of the countries.

Paars.



Edited 1 time(s). Last edit at 09/23/2010 03:03PM by Paars.

Options: ReplyQuote
Re: A new project
Posted by: Paars ()
Date: September 24, 2010 04:34AM

I would like to point to the luck I had earlier and everyone and I know, because I´m Paars it would slap me back in the face 3 times as hard. :) for the past 6 or 7 hours I've been trying to Get my router to forward information to my laptop etc, so I could get the chatsystem to work externally(It works inside the network) First Mcafee started bitching, tho it wasn't officially activated anymore. I tried removing that, but it didn't want too. I tried terminating the processes of it, but 2 couldn't be closed still retried removing it.

Then decided to restart my laptop, obviously it didn't want to do that either. So I just let it crash after restart not much to be found from mcafee luckily. But still no luck at getting anyone to connect to my laptop, nothing found in my logs either. So I went on another destroying software rampage and shutting down any possible security and such firewalls etc etc all down.
Nothing changed yet.

At that time I still had a browserpage opened to my router, when i looked at my processes I noticed it had already taken 700 mb memory. Could be me but I think its a bit much for something that ain't doing a fucking thing.
I tried changing some ports in the router again, but it gave me the weirdest errors about fiels not being filled which I had disabled. I concluded, this router was programmed by one shitty company.

Also after each change I did there was a 50% chance of the router crashing before the saves were finished. I got 'slightly' frustrated. and went through every possible router setting, changing whatever I could change that made a bit of sense.Until into 1 of the last option screens. YES! After that change I couldn't possibly connect to the router at any way, with no pc no laptop, wired or not. I shut down its power, I did a full reset. Nope it didn't work. And I'm glad even tho my nephew brought it home like 3 days ago, its a fucking piece of crap and I hope it burns in hell!

The 7 hours I wasted on this router to not even get a result which I got with the previous router in 30 seconds. I will take that fucking thing outside next and smash into such little piece it gets blown away by the wind.
I'm now posting by being illegally connected to some random neighbors network, to write this message. Wondering what I could've fixed in the time if I had succesfully forwarded this in the 30 seconds I was suposed to.

Peace

Paars.

Options: ReplyQuote
Re: A new project
Posted by: Paars ()
Date: September 24, 2010 02:28PM

So obviously after that I went on a killing frenzy into my neighborhood again. As usuall schools were burning, kids were crying etc etc.

---------------------------------

But actually, my family wanted internet so bad and with no other routers I had and try to fix the same one. Unfortunately I succeeded at that. But with its gay continuing internet drops, I decided it might help to disable the key security etc, instead to put in a mac-adress security. But after 15 minuts the whining began all lost internet and after I looked this stupid fuckin router had changed a lot of information, including deleting the mac-adresses I had put in.
Arggggg Why do you want to hurt me?! Break me down menthally.

So I just took out all of the security, whatever.

----------------------------------------------------

I Continued after that trying to get the lobby system to work and finally after about 11 hours of being menthally raped. I Got the 30 second job to work.

So in conclusion: I fixed the lobbysystem to connect with external networks etc.

Paars

If anyone is interested in trying the chatclient, just ask.

Oh btw, I'm considering an old friend I know From the same Study, to help me with programming as well. His mathimatical thinking is a lot worse, but he has way more experience in java or coding in general for that matter. + He's not as lazy as I when he gets interested in such a thing. He said he had a lot of free time on his hands atm, besides his own lil projects so I probably get him to help me. :)



Edited 1 time(s). Last edit at 09/24/2010 02:34PM by Paars.

Options: ReplyQuote
Re: A new project
Posted by: Paars ()
Date: September 24, 2010 07:06PM

I´d love to continue to program some more. But besides a concentration near zero. + Im starting to show some psycotic like signs it perhaps may be best for me not to continue and get some rest.

Options: ReplyQuote
Re: A new project
Posted by: -RIPPE- ()
Date: October 21, 2010 04:08AM

... and this is how the map of a futurconq may look like. the nuclear fire took down alaska where mexico once was and turned it to marocco. the islands of hawaii travelled a long way all just to get be the fighting grounds between algiers and cyrenaica.



Edited 2 time(s). Last edit at 10/21/2010 04:14AM by -RIPPE-.

Attachments: futurconqmap.jpg (152 KB)  
Options: ReplyQuote
Re: A new project
Posted by: LikeNoOthers ()
Date: October 21, 2010 02:14PM

i fucking love it Rippe

Options: ReplyQuote
Re: A new project
Posted by: -RIPPE- ()
Date: October 22, 2010 04:44AM

thx pal, i didnt put in too much thought of strategic value, it was more a rough idea. i was just about the possibilities with a new map design to convince paars in creating something new. since it could be placed post-nuke i guess everything is possible. of course in this design the east would be quite strong and the map would hardly deliver for 3 vs 3...

just creating a flawless new version of conquerorgame would lack respect and spirit to the original i think and as the children of conq we can do much better! conquerorgame is unique and should stay like it is or develop into a direction alexey wants it to.

but we, we should boldly go where no man or woman has gone before.

Options: ReplyQuote
Re: A new project
Posted by: Paars ()
Date: October 23, 2010 11:19PM

Rippe, I shall reply you in a private message.

grtz paars.

Options: ReplyQuote
Re: A new project
Posted by: Paars ()
Date: January 07, 2011 09:04AM

There's a much of coding done which you can't really see, anyway here a screenshot. Really need someone do to some imaging for me. :D

Attachments: game.jpg (217.6 KB)  
Options: ReplyQuote
Re: A new project
Posted by: Xi ()
Date: January 07, 2011 03:49PM

From that attachment I can deduce that:

a) You can speak dutch as FOK forum is a dutch forum.
b) You have an interest in Chinese novel "Water Margin" or alternatively the game Bandit Kings of Ancient China.
c) You use IE HAHAHAHAHAHA (breath in) HAHAHAHAHAHAHAHAHA
d) You are a great person for programming this for the community.


IE HAHAHAHAHAHAHAHA lord have mercy.

Options: ReplyQuote
Re: A new project
Posted by: Paars ()
Date: January 08, 2011 03:56AM

I use, ie, chrome and firefox. :)

Options: ReplyQuote
Re: A new project
Posted by: Paars ()
Date: January 10, 2011 04:04AM

Alright new image, I still use the old conquerorgame country names.

Attachments: conquerorGameClone.jpg (337.8 KB)  
Options: ReplyQuote
Re: A new project
Posted by: admin ()
Date: January 10, 2011 07:34AM

Hey guys, 2011 is gonna be the year that Conqueror gets rewritten... I kid you not. We will be moving it away from the Shockwave-only thing it is now. More news later!

Options: ReplyQuote
Re: A new project
Posted by: Paars ()
Date: January 10, 2011 07:40AM

I knew about that :), But It wasn't up to me to make that public.

Options: ReplyQuote
Re: A new project
Posted by: MPehrsson ()
Date: January 11, 2011 08:39PM

do your knowledge and intelligence know no boundaries Paars?..
you create new games and you know all about updates on the old one before we even do.
dude I wanna live your life! (:

*seriously hope you are single cause imma go romantic on your ass :P

Options: ReplyQuote
Re: A new project
Posted by: LikeNoOthers ()
Date: January 12, 2011 02:51AM

Gj, MPehrsson, without being just a bit nasty!

Options: ReplyQuote
Re: A new project
Posted by: Paars ()
Date: January 12, 2011 03:08AM

The admin told before in the development subforum, though there wasn't a specific timeline to be told.

Options: ReplyQuote
Re: A new project
Posted by: LikeNoOthers ()
Date: January 12, 2011 09:15AM

Alexey has also been saying it a few times online Conqueror.

Options: ReplyQuote
Re: A new project
Posted by: jenny ()
Date: January 14, 2011 04:27AM

fantastic to hear they are moving away from shock wave... thank you from all mac users!!

Options: ReplyQuote
Re: A new project
Posted by: Paars ()
Date: January 15, 2011 02:38AM

pre bump for the next post of coding, so its get on the first page.

Options: ReplyQuote
Pages: Previous123Next
Current Page: 2 of 3


Sorry, only registered users may post in this forum.