• What Do You Need Help With? V6
    7,544 replies, posted
[QUOTE=c-unit;43534348]Doesn't Python have automatic type conversion? if( /*input*/9 == "9" /*string comparison*/) should return true?[/QUOTE] That's JavaScript. Python has a fairly rigid type system, it's just dynamically typed so you can't verify programs through compiling. On the plus side you don't need interfaces. [editline]14th January 2014[/editline] [QUOTE=Larikang;43535605]I'm making a multiplayer game where all communication uses UDP sockets. I understand that if the server is behind a router, you need to forward ports so that it can receive packets. I haven't been able to test this yet, but wouldn't the clients need to do the same thing? Is there a way to set up the net code so that the clients don't need to port forward to receive packets from the server?[/QUOTE] If they send data to the server first and the server replies back to the port the request is coming from any unmodified NAT should forward them correctly. Please make sure answers to stateless/anonymous requests are no larger than the request package to avoid providing an amplification platform for (D)DoS.
^this
So, i came up with a "should-I-implement-This" question. I am currently writing a spotfiy API, and have a Method called getAlbumArt() which returns the bitmap of the current Album. Since it needs to download it, it needs a bit of time. Should i make an async getAlbumArtAsync() vor should i let the user make their own method?
[QUOTE=johnnyaka;43536290]So, i came up with a "should-I-implement-This" question. I am currently writing a spotfiy API, and have a Method called getAlbumArt() which returns the bitmap of the current Album. Since it needs to download it, it needs a bit of time. Should i make an async getAlbumArtAsync() vor should i let the user make their own method?[/QUOTE] Having the async one would be useful, as the underlying download should already be async enabled. You can also call async functions synchronously without trouble, so you can just use that as default and write a one line synchronous wrapper if you want to provide that too. If Spotify has some kind of rate limiting that drops requests you should have a central dispatcher though.
Okay, yea that makes sense Rate Limiting should not be the problem here, since it's based on a normal webpage, which gets analyzed
[QUOTE=Tamschi;43535656]If they send data to the server first and the server replies back to the port the request is coming from any unmodified NAT should forward them correctly. Please make sure answers to stateless/anonymous requests are no larger than the request package to avoid providing an amplification platform for (D)DoS.[/QUOTE] Cool, thanks. I'm not familiar with the second part, but the server only responds to anonymous messages with a two byte response. That should do it, right?
[QUOTE=Larikang;43537796]Cool, thanks. I'm not familiar with the second part, but the server only responds to anonymous messages with a two byte response. That should do it, right?[/QUOTE] Some game servers send long responses to things like a short query for the server list, which can be used in conjunction with forged packet origins to generate large amounts of targeted traffic. It was a problem recently a few times, iirc some of the Facepunch DoS attacks used Call of Duty servers like this.
[QUOTE=Tamschi;43535656]That's JavaScript. Python has a fairly rigid type system, it's just dynamically typed so you can't verify programs through compiling. On the plus side you don't need interfaces.[/QUOTE] Ah, that's right, because Javascript also has the '===' operator. Makes sense now.
I want to learn Haskell properly because all of the cool kids are using it. I've been messing around with it for a few weeks now but that's too slow, I need a project to work on, I learn much faster that way. Problem is, I can't find a single project that I'm interested in creating in Haskell. Sure I could create a small console game or solve fizz buzz but I've done all of that before in other languages.
This is probably a really stupid question but here goes. So, I use Code::Blocks and GCC. I have a project that will use the source of someone elses SHA1 implementation. I don't want to add the source to that into my project because it's really large. I just want to link to it. I think that's what I am trying to convey. I have tried just including the header like so: [code]#include "path/to/hashlibpp.h"[/code] But when I compile my project I get an error whenever I try to instantiate anything, for example: [code]In function `ZN9MyClassC2Ev': undefined reference to `sha1wrapper::sha1wrapper()'|[/code] [edit] I mean I don't want to add the source to my project because of project view would be a pain in the ass to navigate through.
You need to link with the compiled SHA1 implementation. That can be either dynamically at run time or statically at compile time. I'm not familiar with Code::Blocks. But for GCC dynamic linking would look like [code] gcc ... -L /location/of/lib -lsha1 [/code] That would be if your SHA1 implementation is /location/of/lib/libsha1.so And static linking would be [code] gcc ... libsha1.a [/code] i.e. just add it to list of other objects to link
I don't know what you said or even what I did, but it works and it's magic. Thank you.
Does this async implementation acutally makes sense? Never really worked with async... [CODE] public async Task<Bitmap> GetAlbumArtAsync(AlbumArtSize size) { using (WebClient wc = new WebClient()) { wc.Proxy = null; String url = GetAlbumArtURL(size); using (MemoryStream ms = new MemoryStream(await wc.DownloadDataTaskAsync(url))) { return (Bitmap)Image.FromStream(ms); } } } [/CODE] [CODE] pictureBox1.Image = await e.new_track.GetAlbumArtAsync(AlbumArtSize.SIZE_160); pictureBox2.Image = await e.new_track.GetAlbumArtAsync(AlbumArtSize.SIZE_640); [/CODE]
[QUOTE=reevezy67;43543357]I want to learn Haskell properly because all of the cool kids are using it. I've been messing around with it for a few weeks now but that's too slow, I need a project to work on, I learn much faster that way. Problem is, I can't find a single project that I'm interested in creating in Haskell. Sure I could create a small console game or solve fizz buzz but I've done all of that before in other languages.[/QUOTE] Brainfuck interpreter? Tic-tac-toe? RPN calculator? Normal calculator? Some command line-oriented app? Something visual using gloss library to show something cool on screen quickly?
[QUOTE=reevezy67;43543357]I want to learn Haskell properly because all of the cool kids are using it. I've been messing around with it for a few weeks now but that's too slow, I need a project to work on, I learn much faster that way. Problem is, I can't find a single project that I'm interested in creating in Haskell. Sure I could create a small console game or solve fizz buzz but I've done all of that before in other languages.[/QUOTE] Make a pi visualizer.
[IMG]http://i.imgur.com/MXX6AXl.png[/IMG] answer is supposed to be sent by tcp. I should receive 0x02 and 0x03, but instead i receive all those bytes. Anyone know why this happens? It works fine when i just do answer = "somestring". [img]http://i.imgur.com/rx2Laim.png[/img] So i'm pretty sure the problem is in this piece of code. I'm new to C++ and i'm teaching myself so pretty sure i'm doing something very dumb.
[QUOTE=MatheusMCardoso;43568646][IMG]http://i.imgur.com/MXX6AXl.png[/IMG] answer is supposed to be sent by tcp. I should receive 0x02 and 0x03, but instead i receive all those bytes. Anyone know why this happens? It works fine when i just do answer = "somestring". [img]http://i.imgur.com/rx2Laim.png[/img] So i'm pretty sure the problem is in this piece of code. I'm new to C++ and i'm teaching myself so pretty sure i'm doing something very dumb.[/QUOTE] You are dealing with arrays of undetermined length.[cpp]char _answer[] = {0x02, 0x03};[/cpp]creates an array of length 2, but as soon as you do[cpp]answer = _answer;[/cpp]you are discarding the length information and "answer" will just be a pointer to a (single) character. Any function trying to treat it as a string of characters will then continue to read bytes until a terminating '\0' comes along.[cpp]answer = "something";[/cpp]is the same as if you would do[cpp]char _answer[] = {'s', 'o', 'm', 'e', 's', 't', 'r', 'i', 'n', 'g', '\0'};[/cpp]and contains the termination byte.
I get it, but how do i assign my char* answer to an array like {0x2D, 0x59, 0x78, ...} This is how i'm sending the answer: [code] send(client, answer,strlen(answer),0); [/code] i guess i have to do something about that strlen? My google is all purple already.
[QUOTE=MatheusMCardoso;43568769]I get it, but how do i assign my char* answer to an array like {0x2D, 0x59, 0x78, ...} This is how i'm sending the answer: [code] send(client, answer,strlen(answer),0); [/code] i guess i have to do something about that strlen? My google is all purple already.[/QUOTE] strlen() counts the characters until it finds '\0'. In general, you have two choices. Either send a char* that is supposed to be null-terminated string at all times (make sure to append '\0') or send a byte buffer consisting of a char* plus a size_t for the length of the data, e.g. in a struct.
I tried doing [code] _answer = {0x02, 0x03, 0x0} answer = _answer; [/code] But i receive 0x60 and 0x4C. I think the second approach would still produce undesired output.
[QUOTE=MatheusMCardoso;43568811]I tried doing [code] _answer = {0x02, 0x03, 0x0} answer = _answer; [/code] But i receive 0x60 and 0x4C. I think the second approach would still produce undesired output.[/QUOTE] Are you returning "answer"? Because it points to stack-allocated data which gets destroyed after the function returns.
[QUOTE=Dienes;43568826]Are you returning "answer"? Because it points to stack-allocated data which gets destroyed after the function returns.[/QUOTE] Yes :v: I'm new to this low-level stuff. What should i return?
[QUOTE=MatheusMCardoso;43568833]Yes :v: I'm new to this low-level stuff. What should i return?[/QUOTE] You cannot return an array unless you allocate it on the heap, but then the caller has to take care of destruction, which is not a good approach. The common way to do it is to take an additional argument where the caller provides a pre-allocated buffer in which you can store your data, then return the amount of bytes you have written. To be safe, you can also add a third argument for the buffer size, so you do not overrun it.
[QUOTE=Dienes;43568859]You cannot return an array unless you allocate it on the heap, but then the caller has to take care of destruction, which is not a good approach. The common way to do it is to take an additional argument where the caller provides a pre-allocated buffer in which you can store your data, then return the amount of bytes you have written. To be safe, you can also add a third argument for the buffer size, so you do not overrun it.[/QUOTE] I knew something like that would work. Many thanks.
I'm trying to make a batch file to turn on the sound in safe mode. Here's the code: [code] @echo off cls echo. echo Hello, %username%. echo This program will enable the sound service. echo. :case_1 call:print "Attempting to start Windows Audio..." call:check_audio "sc start AudioSrv" "case_2" :case_2 call:print "Attempting to start Windows Audio again..." call:check_audio "C:\Windows\System32\svchost.exe -k LocalServiceNetworkRestricted" "case_3" :case_3 echo. echo Attempting to start dependencies... echo. call:print "Starting Multimedia Class Scheduler..." call:check_active "MMCSS" "sc start MMCSS" "case_4" "Multimedia Class Scheduler" call:print "Starting Remote Procedure Call (RPC)..." call:check_active "RpcSs" "sc start RpcSs" "case_4" "Remote Procedure Call (RPC)" call:print "Starting Windows Audio Endpoint Builder..." call:check_active "AudioEndpointBuilder" "sc start AudioEndpointBuilder" "case_4" "Windows Audio Endpoint Builder" call:print "Attempting to start Windows Audio again..." call:check_audio "sc start AudioSrv" "case_4" :case_4 echo. echo Attempting to start dependencies again... echo. call:print "Starting Multimedia Class Scheduler..." call:check_active "MMCSS" "C:\Windows\system32\svchost.exe -k netsvcs" "error" "Multimedia Class Scheduler" call:print "Starting Remote Procedure Call (RPC)..." call:check_active "RpcSs" "C:\Windows\system32\svchost.exe -k rpcss" "error" "Remote Procedure Call (RPC)" call:print "Starting Windows Audio Endpoint Builder..." call:check_active "AudioEndpointBuilder" "C:\Windows\System32\svchost.exe -k LocalSystemNetworkRestricted" "error" "Windows Audio Endpoint Builder" call:print "Attempting to start Windows Audio again..." call:check_audio "C:\Windows\System32\svchost.exe -k LocalServiceNetworkRestricted" "error" :print echo %~1 echo. :check_audio :: Checking if Windows Audio is active. If it is unable to be activated, GOTO <label>. :: If it has already been activated, GOTO exit. for /f "tokens=3 delims=: " %%H in ('sc query "AudioSrv" ^| findstr " STATE"') do ( if /i "%%H" NEQ "RUNNING" ( :: Tokenises line containing service's state, pulls out third token. :: Tests resulting state against the string, "RUNNING". %~1 || goto %~2 ) else ( goto quit ) ) :check_active :: Checking if service is active. If it is unable to be activated, GOTO <label>. :: If it has already been activated, state that it is already running. for /f "tokens=3 delims=: " %%H in ('sc query "%~1" ^| findstr " STATE"') do ( if /i "%%H" NEQ "RUNNING" ( %~2 || goto %~3 ) else ( echo %~4 is already running. ) ) :error :: States what error the program failed with and exits. echo Program failed with error #%errorlevel%. exit /b %errorlevel% :quit call:print "The program was successful. Windows Audio is running." pause exit [/code] It seems to work fine, except it generates an infinite loop when calling the check_audio or check_active functions. Why is this?
Anyone know anything about hooking x64 code/know any good APIs? I have little [URL="http://youtu.be/7PQIBD_l6Qg"]tool[/URL] that works by injecting a .dll to the game. In the 32-bit .dll I use MS Detours 1.5 which isn't compatible with 64-bit code and I've tried a few APIs already but I'm having problems getting any of them to work.
Not sure where else to ask for help so.. [cpp] [bits 16] [org 0] jmp 0x7C0:start start: mov al, 0xAA xor bx, bx mov dx, [0x400] ; Address of first serial port mov bx, 0xAAAA out dx, [bx] halt: jmp halt times 510 - ($ - $$) db 0 dw 0xAA55[/cpp] Trying to assemble with NASM but it keeps getting stuck on [b]out dx, [bx][/b] with the error: [i]error: invalid combination of opcode and operands[/i] I've double checked the instruction and it appears to be correct so I have no idea what is going on.
You can only use the A-register as secondary operand to the out instruction (IA-32). So just mov [bx] there (or [0xAAAA] directly) and do out dx, {al,ax,eax} (depending on the size of the data at [bx]).
[QUOTE=ZeekyHBomb;43582412]You can only use the A-register as secondary operand to the out instruction (IA-32). So just mov [bx] there (or [0xAAAA] directly) and do out dx, {al,ax,eax} (depending on the size of the data at [bx]).[/QUOTE] Thank you! I've been pulling my hair out over that. Guess I need to read the instruction description more carefully in future.
So i'm dealing with induced subgraph isomorphism problem. This means that you have two undirected graphs G and H and one must determine whether G contains a subgraph that is isomorphic to H, so in other words, you project all the Vertices from G in certain Vertices in H and edges must match. For example in [url=http://shrani.si/?3s/od/w6Dh65G/primer1.png][img]http://shrani.si/t/3s/od/w6Dh65G/primer1.jpg[/img][/url] one of the isomorphisms is G -> H 0 -> 2 1 -> 5 2 -> 3 this is not a valid one G -> H 0 -> 0 1 -> 1 2 -> 2 because edge between 1 and 2 does not exist in G For the assignment i have to print all possible isomorphisms(print order not relevant). I took care of the input but now i don't know how i would make a time efficient algorithm(it must be [B]authentic and not too complex[/B] so Ullman's algortihm does not count). my code so far [code] import java.util.ArrayList; import java.util.Scanner; class Vertex{ int id; ArrayList<Integer> net; public Vertex(int id){ this.id = id; net = new ArrayList<Integer>(); } public void addEdge(int neighbour){ net.add(neighbour); } } public class Isomorphism{ public static void main(String [] args){ Scanner sc = new Scanner(System.in); int n1G = sc.nextInt(); //number of vertices in G int n2G = sc.nextInt(); //number of edges in G ArrayList<Vertex> graphG = new ArrayList<Vertex>(); //add vertices to G for(int i = 0; i < n1G; i++) graphG.add(new Vertex(i)); //add edges to G for(int i = 0; i < n2G; i++) graphG.get(sc.nextInt()).addEdge(sc.nextInt()); int n1H = sc.nextInt(); int n2H = sc.nextInt(); ArrayList<Vertex> graphH = new ArrayList<Vertex>(); //add vertices to H for(int i = 0; i < n1H; i++) graphH.add(new Vertex(i)); //add edges to H for(int i = 0; i < n2H; i++) graphH.get(sc.nextInt()).addEdge(sc.nextInt()); //find possible isomorphisms } } [/code]
Sorry, you need to Log In to post a reply to this thread.