Jump to content
  • Advertisement


  • Content Count

  • Joined

  • Last visited

Community Reputation

120 Neutral

About Xer0botXer0

  • Rank

Personal Information

  • Interests

Recent Profile Visitors

1703 profile views
  1. Xer0botXer0

    Java Server Q&A

    So I was able to receive the information I wanted, One thing that's come up is the client disconnecting, from what I gather, with the following code I would need to close all four streams and backwards in the way they were created, I would then close the socket, and then since I'm not using the class object anymore I could destroy that too ? package LearningProject; import java.io.*; import java.net.*; public class Player { Socket my_Sock; private DataInputStream dis; private DataOutputStream dos; private BufferedInputStream bis; private BufferedOutputStream bos; boolean keep_Alive = true; byte buffer_u8; //8bit integer 0 - 255 byte[] buffer_u16 = new byte[2]; //16bit 0 - 65,535 byte[] buffer_u32 = new byte[4]; //32bit 0 - 4,294,967,295. byte[] buffer_get_all = new byte[1000]; //1kb with 1000 ASCII characters Integer[] msg_Types = new Integer[5]; public Player (Socket sck) { my_Sock = sck; Setup_Create_Streams(); Setup_Message_Types(); Monitor_Incoming(); } void Setup_Create_Streams() { try{ bis = new BufferedInputStream(my_Sock.getInputStream()); bos = new BufferedOutputStream(my_Sock.getOutputStream()); dis = new DataInputStream(bis); dos = new DataOutputStream(bos); }catch(IOException e) {System.out.println("Unable to create Input/output Streams.");} } void Setup_Message_Types() { msg_Types[0] = 51; // Client says hello msg_Types[1] = 20; //CLient says good bye } void Monitor_Incoming() { Integer receive_msg_id = null; Integer buffer_Size = 0; try{ receive_msg_id = dis.readUnsignedByte(); System.out.println("Message_ID: " + receive_msg_id); for (int i = 0; i < msg_Types.length; i ++) { if (receive_msg_id == msg_Types[i]) { buffer_Size = dis.readUnsignedByte(); System.out.println("Buffer size: " +buffer_Size); Handle_Data(buffer_Size,receive_msg_id); } } }catch (IOException e){System.out.println("Error receiving bytes."); } } void Handle_Data(Integer buff_size,Integer msg_id) { switch(msg_id) { case 51: { try { dis.read(buffer_get_all,2,buff_size); String Receive_greeting = new String(buffer_get_all, "UTF-8"); System.out.println("Greeting: " + Receive_greeting); } catch (IOException e) {System.out.println("Failed to handle data, see Msg_ID: " + msg_id); } } } } } Output: So I'm quite happy with this so far. I just need to go over it because I have uncertainties, I haven't tested this with multiple incoming packets so I don't know what errors I may get, I haven't worked out how to handle disconnecting clients yet, maybe even a keep-alive ping kinda thing too, and am I taking the right approach to reading the incoming data, do I even need DataInputStream when I can just read the bytes from the BIS.. my gml server is pretty simple, it just looks at the data type then reads what ever comes next into their respective variables with specified data types and then makes what ever calculations. I want this to be pretty much the same. Tomorrow I'll carry on with this and then go on with responding so sending packets from the server to the client. There's still a lot to do like I'm sure I'd like to use multithreading later on, I plan on using a sql data base for storing all game info, ah yeah the gml server only has one sql extension for it. I was previously using ini files to save information but was limiting and ugly. gml servers also cant be run on dedicated servers due to the gui without spending extra. I think Java has a lot of benefits over a gm server. Oh and then there's actually making stuff happen in the gm game.. don't want to think about that for now.
  2. Xer0botXer0

    Java Server Q&A

    Thanks that's actually pretty good. I've never used buffer_seek to move around a buffer, I'm actually asking about that on the forum.. I know we've gone through a lot of bits and bytes stuff but what came to me now is knowing what set of bits/bytes belong to which variable and read as what data type. Here's what I posted there Code: ///SEND buffer_seek(buff, buffer_seek_start, 0); buffer_write(buff, buffer_u16, 5); buffer_write(buff, buffer_u8, 51); buffer_write(buff, buffer_string, "Hello Server!"); network_send_raw(client, buff, buffer_get_size(buff)); Code: ///RECEIVE var val1 = buffer_read(buff,buffer_u16); var val2 = buffer_read(buff,buffer_u8); var val3 = buffer_read(buff,buffer_string); So my question is, how do the reading buffers know what part of the written buffers to read, which should be read, so how does val1 know not to read the value "5" and the value"51, and that only "5" belongs to val1 ? My assumption is the way bits work, 8 bits in a byte, since 1 byte is used to represent the english language on what I'm assuming GML uses the UTF-8 Table, then only 1 byte has a value, where the other byte since it's a u16 should be empty ? or am I missing something. buffer_u16 can represent values from 0-65,535 but at the moment it only represents the value 5, so there should be a whole lot of 0s there.. are those 0s being sent with ? so buffer_write sends this 00000000 00000101 and buffer_read (in order since TCP) will get those bits as they are there ? I brought this up because on the server I will be able to get the total amount of incoming data, I then use the BIS method which stores a length or received bytes from a set position into a byte array, and then from there I would read bytes from say 9-16 and read it as a 8 bit integer, 17-24 as an 8 bit, but now what about strings.. All I got was the length of all the bytes in total, but I never got the length for each individual message that needs to be read, for stacked integers it's fine but what about a message. I need to see strings the way I see integers, if I'm sending an 8 bit integer, and I'm expecting an 8 bit integer, then I need to send a predefined sized string too so that I can expect that same size in return. But this all depends on the question. So I found out that in GML the buffer_string data type has a null terminating character 0x0. I see that's the ASCII reference to null. This is where it brings up high bits and so on.. Time for lunch.
  3. Xer0botXer0

    Java Server Q&A

    Ah ordered messages sounds useful, anything else would break my programs. well I'm trying to go with sending the packet size, here's my gml code ///Run once say hello if run_once == false { buffer_seek(buff, buffer_seek_start, 0);//Go to the start of the buffer buffer_write(buff, buffer_u8, 51);//MSG_TYPE buffer_write(buff, buffer_u8, buffer_get_size(buff));//Buffer Size buffer_write(buff, buffer_string, "Hello Server!");//Message network_send_raw(client, buff, buffer_get_size(buff));//Send the package to the server run_once = true; } So first message tells the server the message type, second is suppose to tell the server the size of the buffer, the third and so on being the messages and then I send the packet. So I don't get how I would send the packet size without first writing everything into the buffer, I'm on the gml forum now because network_send_raw for some reason has the third parameter that gets the buffer size too, so I'm hoping that it sends the buffer size anyway. if it were a java client how would you approach this ? I have an idea that what I can do is get the bytes of everything that I send to the server for example ///Run once say hello if run_once == false { buffer_seek(buff, buffer_seek_start, 0);//Go to the start of the buffer var msg_type = string_byte_length(String(51)); var msg_1 = string_byte_length("Hello Server!"); var get_buff_size = msg_type + msg_1; buffer_write(buff, buffer_u8, msg_type);//MSG_TYPE buffer_write(buff, buffer_u8, get_buff_size);//Buffer Size buffer_write(buff, buffer_string, msg_1);//Message network_send_raw(client, buff, buffer_get_size(buff));//Send the package to the server run_once = true; } This could work I believe but now I still wonder why network_send_raw uses buffer_get_size, I'll have to see what people say on the GML forum, if all is okay then I'd have to make scripts/methods to convert these things more easier.
  4. Xer0botXer0

    What are bytes

    Oh snap, I forgot about kilobytes. Thank goodness.
  5. Xer0botXer0

    What are bytes

    Am I correct in saying that a MB can hold 1024 ASCII characters, since these characters include the alphabet, spacing and numbers I need to create a byte array that will store say chat messages, I don't want to make it too small and will adjust it later but I just want to confirm before I continue. I'll be converting bytes to the UTF-8 table, from what I read there are different levels at which bytes are used. 1 byte will support all the ASCII characters, 2 bytes are for other languages, 3 for japanese and so on and yeah I just want to focus on 1 byte for now. I think Java has a library that lets me convert bytes to the UTF-8 table. So originally I wanted to use a BufferedInputStream to read bytes sent from a client to the server(yes I know I have a post for server stuff but shit which thread do I post this on), from there I use a DataInputStream with the BIS, from my understanding BIS reads bytes, DIS converts bytes to a data type. wait ..I just saw DIS has .readUTF! Does that mean that if someone sends the server a string in Japanese, the server will be able to read the bytes and convert it to Japanese ?
  6. Xer0botXer0

    Java Server Q&A

    Hi Kylotan, thanks for the answers I actually just came here to ask about knowing how much data is going to be received. The other thing is to identify requests and data that comes with it from the client, say I want to tell the server hey the player wants to move, so I need to start with a unique ID, then the length of the following incoming data. I'm going to give this a try and see what comes up. Also my idea behind this is to use a bufferedinputstream to get the socket inputstream, and then place the bufferedinputstream inside of a datainputstream, from what I remember low level stream means it works with bytes, high level works with data types, dis is high level, and bis is low level so that 'stack' should work. from there I just need to figure out what's being sent and so on. I was thinking as an alternative to sending the size, Instead I could send a unique Short value to say 'this is the end of this packet'. With a unique short value as the ID for the start of a packet. I think that might work but I'm a bit worried that I might lose packets if I were to use udp instead of tcp, i've heard about rudp which is where the developer would make it reliable by doing something similar to tcp by checking to see if all packets were received. something I haven't wrapped my head around is that even the 'checks' could become lost packets. my guess is that the checks come first before unique IDs/lengths and so on, so if the check doesn't arrive then don't process the incoming information, at that point the server would have to tell the client hey send that again i didn't get that or rather if it does arrive the server tells the client it arrived, so if the client doesn't get that the packet you sent has arrived then resend it. but then it's a matter of how soon should it be resent. but ill get to that later lol So far I've only been able to receive bytes individually, I'd declare a byte bytes[]; array but the bytes won't concatenate. maybe using the dis will change that. It's kinda fun to see how these things work
  7. Xer0botXer0

    What are bytes

    I said that because I thought that bits were too small to represent numbers. What I'm starting to understand is that the values bits represent is based on which table is used so for example without a table like the ASCII table we wouldn't be able to have characters and such. we'd still only have ones and zeros. I was trying to see the significance between having multiple data types, I couldn't really find a question regarding it that mattered other than one thing that comes up, if 01100001 can represent 97 and a, then how does the computer tell which one is say ..being received from a buffer ? I thought maybe if the data type was string instead of int then it would know it's an 'a' but strings can have numbers in them too. so the guy in this post is saying that when ever the computer receives input the data type for each character/letter or what ever the word for it is - is remembered.. that kind of would make sense .. I'm wondering how a computer remembers this stuff. But now what if I've got a string "Hello 1234" and I send that to a client, I'm not sure what the binary values for H and 1 is but pretending they're the same, how then would the client know that the one's a character and the other the number ..and not "1ello 1234/Hello H234"
  8. Xer0botXer0

    What are bytes

    So 8 bits in a row makes 1 byte, and then as you say depending on the amount of bytes in a row changes the way it's interpreted ? So I had a look at binary counting, so 00100 is four in binary. and five would be 00101. both of them are five bits though ? Without both the client and server knowing what the values represent so without the metadata saying if you get these eight bits then it's a byte.. Can you tell me this, so if I send a 8 bits from client to server, the server knows it's a byte, but because of some calculation in the code, when I sent the byte the server can tell that the byte represents the number 5 because of the switch positions (the bits) being 0 or 1 ? Like I'm starting to see the use of bits if I'm right about the above, but how far can bits represent things, bits alone mean nothing unless grouped up into bytes ? mainly because numbers and characters and such can't be represented in bits alone ? I'm still missing something here. Should I be looking at how bits/bytes and such are used when it comes to Unicode ? https://en.wikipedia.org/wiki/Unicode Or rather ascii ? Not sure but I found a page regarding Binary code. I'm guessing that should provide some leads. So I just found that 01100001 can be 97 but it can also be the lower cased 'a' character. depending on the encoding. Is this the reason data types are specified ?
  9. Xer0botXer0

    What are bytes

    Hi guys, so I feel like I'm going to have to mess around with java functions for a while because this is confusing me. I have a java server and a GML client, the client sends information to java via buffers, it has a few data types, string, u8, u16, signed too, long and so on. I could work with all that because I knew that I wanted to use the relevant data type as in if i'm working with strings I'll use the buffer_string type, if I'm working with small values up to 256 i think I'd use buffer_u8, and so on keeping the buffer size large enough for it's purpose and not much larger. Now that I have a java server a few things confuse me, things that happened behind the scenes with Game maker studio, for 1 there is overhead stuff that was going on, there's an option with gml that lets you choose between gml overhead stuff and the other that removes that.. the overhead was like handshaking or something like that.. I believe there are other things that also play a role like sending buffer sizes. But I might be wrong. What I need to do is see exactly what is being sent from the gml client, I don't know how to do that, what I've tried is sending an u8 value 0-256 ( i believe) from gml client to java server receiving as type "Short", I sent a single value of '5'. Now what I don't understand is that there has to be more to it, I'm not receiving this 'buffer_size' that gml is supposedly sending. or rather if I am then how do i see it ? Which brings me to array of bytes, I know what an array is, I dont really know what bytes are and yet I work with them, I know they're larger than bits and smaller than kilo bytes, a way of measuring the size of something, but what exactly ? When I am streaming data back of forth regardless of data type, am I simply sending bytes back and forth ? The reason I ask is because I don't have a good understanding of how to set up the code on the server and possibly on the client to receive the information properly and in order. Originally in GML the client for example will send a string/integer/etc to the server, it will tell the server the size of the string and the data type used so that the server knows that a string is being received and this is the size of it, honestly I never asked why the size of it mattered. couldn't it just read until a line break or something ? I'm sure the devs of the language had their reasons, I'm primarily concerned with what's relevant to my problem. Anyway and the server will read it, that was all there was to it for me. now with java I believe there's much more to it, in java I don't see functions like.. output = new DataOutputStream(my_Sock.getOutputStream()); output.writeString output.write'u8 output.write'u16 It doesn't seem as simple as that, well I do see I've got writeInt and writeChars which seems like what I would think about using, but under writeInt F2 brings this up: writeInt public final void writeInt(int v) throws IOException Writes an int to the underlying output stream as four bytes, high byte first. If no exception is thrown I've no idea what writing something as four bytes means, and high byte first ? what's a high byte. In fact when ever it talks about bytes and so on I'm expecting this stuff to be sent/received, so I'm expecting that four bytes of data is going to be sent if I use output.writeInt(...); but I'll pretend to know what bytes are and say what if I use values in the writeInt method larger than four bytes? As you can see there's a lot of confusion here but to the trained eye someone might be able to suggest a course of action like what manual or such can I look at to get a better understanding of what's going on here. Whilst I just leave this here and hope someone picks it up I'll be reading on further, thanks for reading hope to get some replies.
  10. Xer0botXer0

    Java Server Q&A

    Okay according to these docs https://docs.oracle.com/javase/8/docs/api/java/io/DataOutputStream.html there are various methods for sending different types of data, I think that answers my question, the same with DataInputStream. I'm wondering about this do{//Start a do while loop while run is true Socket newConnection = server.accept();//Check if we have a connection, if we do continue otherwise try again String name = "guest"+ply;//Select an unique name for this player Player p = new Player(name, newConnection);//Create a new Player instance and set the socket to it System.out.println("New Player Connected from IP: "+newConnection.getInetAddress()+" and was assigned the name "+name);//Display the message that we got a new player ep.execute(p);//Assign the player instance a thread players.put(name, p);//Add the player instance to the player HashMap }while (run); Within this do while loop line 2 looks for incoming connections right, what I'm wondering is if line 2 doesn't get a connection does line 3 not run ? I'd think the rest of the code within the do while loop would still run. But it makes sense that it shouldn't else errors would occur. The same thing is happening here public void run() { do{//Start a do while loop while alive is true checkForMessages();//Check for messages }while(alive); try { socket.close();//Close and Free the socket from memory } catch (IOException e) {//If we get an exception we coudn't close the socket System.out.println("We got an error while closing a socket on player "+name+"."); } } The guy has a do while loop that runs a method while the alive bool is true, but he also has a try catch statement within the run method, the try catch statement tries to close the player socket, is the do while loop going to run until alive is false before the try catch statement will run ?
  11. Xer0botXer0

    Java Server Q&A

    Hi guys, so I'm trying to make sense of streams, i understand there's an input and an output stream and that these have purpose specific streams. From what I read Byte Array streams are 8-bit, and then fileinputstream/outputstream are 16bit, does this mean that's the max size that each type can hold ? does someone have a table for this. The problem is in GML (Game maker studios language) has buffers and reading a buffer is something like this incoming_data = buffer_read(buffer, buffer_type); Where buffer type can be any of these https://docs.yoyogames.com/source/dadiospice/002_reference/buffers/using buffers.html buffer_u81 An unsigned, 8bit integer. This is a positive value from 0 to 255. buffer_s81 A signed, 8bit integer. This can be a positive or negative value from -128 to 127 (0 is classed as positive). buffer_u162 An unsigned, 16bit integer. This is a positive value from 0 - 65,535. buffer_s162 A signed, 16bit integer. This can be a positive or negative value from -32,768 to 32,767 (0 is classed as positive). buffer_u324 An unsigned, 32bit integer. This is a positive value from 0 to 4,294,967,295. buffer_s324 A signed, 32bit integer. This can be a positive or negative value from -2,147,483,648 to 2,147,483,647 (0 is classed as positive). buffer_f162 A 16bit floating point number. This can be a positive or negative value within the range of +/- 65504. (Not currently supported!) buffer_f324 A 32bit floating point number. This can be a positive or negative value within the range of +/-16777216. buffer_f648 A 64bit floating point number. This can be a positive or negative value from -(252) to 252 - 1. buffer_bool1 A boolean value. Can only be either 1 or 0 (true or false) buffer_stringN/A This is a UTF-8 null terminated (0x00) string. Basically a GameMaker string is dumped in the buffer, and a 0 is put at the end. I can't send incorrect types from the java server to the gml client, but I have the idea that Java has a universal stream that will read what I want to send from the server whether it be a string/u8/u16. These are the three I primarily use. Any advice on which stream type I should use for stuff like that ? And from there I'm not yet sure how sending works, im GML It would work something like this GML Client: msg_id = 32;//32 represents player is sending registration username/pass buffer_seek(buffer, buffer_seek_start, 0); //buffer reference, base position to read/write from, offset from position +/- buffer_write(buffer, buffer_u8,msg_id); buffer_write(buffer,buffer_string,my_username); buffer_write(buffer,buffer_string,my_pass); network_send_packet(socket,buffer,buffer_tell(buffer)); //buffer tell looks at the size of the buffer and sends that too. I'm not sure how the receiving end handles that im going to check out the GMS forum but I'm guessing that information can be seen on java when reading and printing incoming information ? GML Server: Asynchronous Event: ///Handle clients var client_sock = ds_map_find_value(async_load, "socket"); //incoming client socket var net_type = ds_map_find_value(async_load, "type"); switch(net_type) { case network_type_data: //work with data[Info] { //prepare incoming data to be read [Info] var client_id = ds_map_find_value(async_load, "id"); var buff = ds_map_find_value(async_load,"buffer"); buffer_seek(buff,buffer_seek_start,1); var msg_type = buffer_read(buff,buffer_u8); switch(msg_type) { case 10: //Client player is pending registration (usn/pass) { reg_usn = buffer_read(buff, buffer_string); reg_pass = buffer_read(buff, buffer_string); When ever the server detects incoming data it will show which client is sending the data via the first line where the client socket is stored in a ds_map called async load, from there - there are three states to read, Connecting clients, Disconnecting clients and Data flow, in this case it's the data flow one which has a constant called network_type_data. The main thing here is that the incoming buffer is stored in the ds_map "buffer", in the client side you can see I sent three values, a u8, a string and another string. in the server you can see I read the first one and stored it in msg_type, the second in reg_usn and third in reg_pass. so in GML the types had to match. I used the correct data types buffer_u8, buffer_string and buffer_string. I know how to get the sockets with java of gml clients and vice versa, so i believe the next step is sending a message, but when the server responds or sends something to the client it needs to be the right type, so with the image I provided can someone explain which will allow me to use u8,u18 & Strings ?
  12. Xer0botXer0

    Java Server Q&A

    Hi again! while (online) { Socket new_Client = server.accept(); connected_Count += 1; if (new_Client != null) { Player p = new Player(); new_Client = null; } } So I've got a question regarding this code, This is in my main method, Basically what my idea is to look for a new connecting socket and when one is found or when new_Client has a value then create an object of Player then reset new_Client so that the 'setup code' only happens once per new client. The thing is I also have Socket new_Client at the start, so I'm wondering if Socket new_Client is going to create hundreds of new_Clients instead of use the same one ? because I'm declaring new_Client in the while statement, if so my work around is to declare new_Client before the while statement. Second thing is I'm getting a message "The value of the local variable connected_Count is not used" I've declared int connected_Count = 0; at the start of the main method then within the code above you can see I'm incrementing it by one, I also added a println function for connected_Count and still getting that message ?
  13. Xer0botXer0

    Stop hacking

    You could check to see if a specific process is running on the target machine, if it is then close the game or uninstall the program running the specific process. But then they can just rename it, you'd then look at more specific things about the program but yeah I wouldn't bother with that. My approach is the suggestion approach, I'll write the client so that it prevents the player from trying weird stuff, while writing the server so that it doesn't accept any weird stuff, my first goal is to get the client/server working so say x/y coordinates, player logs into the server, player gets player data, player spawns at default coordinates, player starts walking around.. so player presses W the server will receive the input and update the players position based on the speed the player is going and the direction, when the player releases W the server will receive the key release information and stop the player from moving. So even if the player somehow prevents the W release from being sent, the player would stop moving client side but server side the players still gonna move.. which isn't beneficial to the player. the player could try to teleport using say Cheat engine but the server monitors the client side current position, this is where you move past just getting the client server connection to work you're now starting to monitor player activity, so first things first this could be lag or something, so don't just ban the player, maybe try to reconnect the player after doing a ping test, if the ping works fine and the player is still connected then he's trying to hack so either way teleport him back to the last known state of what ever changed. I dont know what those apps are you're talking about but as long as the client cannot COMMAND the server, then there's no way that they can hack anything meaningful. Then it falls down to BUGS and glitches where they somehow managed to open up a chest and loot it twice. That's a different story.
  14. Xer0botXer0

    Storing hashes as game states

    I would use a 2D array, because the way you're doing it it seems like you'd have to sent that entire string back and forth ? maybe not. Also with 2D arrays you can use the first dimension to represent a piece on the board, and the second dimension values to represent the piece type, coordinates, can it move(bools) and link it to its movement type. 2 of those and you'd have one for yourself and one for your opponent.
  15. Xer0botXer0

    Java Server Q&A

    Naturally I'd print the error message! I'm not working on the server at the moment, Since I had a problem with BufferedStream I ended up getting some Java books to help me. I see in chapter four it covers BufferedStream how ever I'm only at chapter three now, and it's a huge chapter! I'm fine with that because since I started I've learnt about some fun and interesting concepts. Eventually the plan is to get to java.io* stuff. So I'll post in this thread once I've gotten back to working on the server.
  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!